<div id="Grid"></div>
<script type="text/javascript">
$(function () {// Document is ready.
//oData Adaptor with DataManager
var dataManager = new ej.DataManager("http://mvc.syncfusion.com/Services/Northwnd.svc/Foods");
$("#Grid").ejGrid({
dataSource: dataManager
});
});
</script>
My question is how do i connect to northwind(Or any database my local SqlServer) from DataManager
the URL is confusing... does DataManager can connect to SqlServer ? Or SqlDataSource
thanks for your help
mk
|
<javascript> <div id="Grid"></div> <script type="text/javascript"> $(function () { $("#Grid").ejGrid({ dataSource: ej.DataManager({url:"/api/GridApi/getData"}), }); }); </script> <API controller> public class GridApiController : ApiController { NORTHWNDEntities db = new NORTHWNDEntities(); public object getData() {
var queryString = HttpContext.Current.Request.QueryString; int skip = Convert.ToInt32(queryString["$skip"]); int take = Convert.ToInt32(queryString["$top"]); var data = db.Orders.Skip(skip).Take(take).ToList(); return new { Items = data.Skip(skip).Take(take), Count = data.Count() };//return a data and count } } |
Venkatesh Ayothiraman.
Kalai Sirajeddine.
|
<ej-grid id="FlatGrid" allow-paging="true">
<e-datamanager adaptor="remoteSaveAdaptor" insert-url="/Home/Insert" update-url="/Home/Update" remove-url="/Home/Delete" json="(IEnumerable<object>)ViewBag.datasource"><e-datamanager></e-datamanager>
dataSource: ej.DataManager({
json : "data"
adaptor: "remoteSaveAdaptor",
insertUrl:"/Home/Insert" ,
updateUrl:"/Home/Update" ,
removeUrl:"/Home/Delete",
}),
<e-columns>
………..
<e-column field="ShipCity" header-text="Ship City" width="110"></e-column>
</e-columns>
</ej-grid>
<script>
var data = @Html.Raw(Json.Serialize(ViewBag.datasource));
</script>
|
Kalai Sirajeddine.
|
<ej-tab id="tabSample" item-active="onactive"
<e-tab-items>
<e-tab-item id="Mobile" text="Testing">
/…
</e-tab-item>
<e-tab-item id="MVC" text="Book1">
<e-content-template>
<div>
// TreeGrid
</e-content-template>
</e-tab-item>
</e-tab-items>
</ej-tab>
|
|
<script type="text/javascript">
function itemActive(args) {
//returns current active index.
if (args.activeIndex == 1) {
var obj = $("# TreeGridContainer ").data("ejTreeGrid");
if (obj) {
obj.setModel({ "sizeSettings": { "height": "350px", "width": "100%" } });
}
}
}
</script> |
|
<ej-tree-grid id="TreeGridContainer" datasource="ViewBag.datasource"
action-complete="ActionComplate" end-edit="EndEdit"
//..
>
</ej-tree-grid> |
|
<script type="text/javascript">
function EndEdit(args) {
var editedRecord = (args.requestType == "update") ? args.currentValue : args.data.item;
//This varible holds the data of the edited record. You can updated it to your remote datasource
$.ajax({
type: "POST",
url: "/Home/Update", //Update is Server side method
data: editedRecord,
dataType: "json",
});
}
function ActionComplate(args) {
var record = args.data;
if (args.requestType === 'addNewRow') {
//Newly Added Record is obtained here , which can be updated to database
addedRecord = args.addedRow;
$.ajax({
type: "POST",
url: "/Home/Add",//Add is Server side method
data: addedRecord,
dataType: "json",
});
} else if (args.requestType === 'delete') {
var deletedRecord = args.data.item; //This is the deleted item.
$.ajax({
type: "POST",
url: "/Home/Delete", //Delete is Server side method
data: deletedRecord,
dataType: "json",
});
if (args.data.hasChildRecords) {
deleteChildRecords(args.data);
}
//If deleted item has child records, we need to delete that too
}
}
//Delete inner level child records
function deleteChildRecords(record) {
var childRecords = record.childRecords,
length = childRecords.length,
count, currentRecord;
for (count = 0; count < length; count++) {
currentRecord = childRecords[count];
var deletedChildRecord = currentRecord.item; //This is the deleted child item.
//If the above deleted child record has child records, then we need to delete that too.
if (currentRecord.hasChildRecords) {
deleteChildRecords(currentRecord);
}
}
}
</script> |
|
<ej-tree-grid id="TreeGridContainer"
id-mapping="TaskId"
parent-id-mapping="ParentId"
//…
>
</ej-tree-grid> |
Kalai Sirajeddine.
Kalai Sirajeddine.
|
function endEdit(args) {
var editedRecord = (args.requestType == "update") ? args.currentValue : args.data.item;
//This varible holds the data of the edited record. You can updated it to your remote datasource
$.ajax({
type: "POST",
url: "/Tab/Update", //Update is Server side method
data: editedRecord,
dataType: "json",
});
} |
|
[HttpPost()]
public ActionResult Update(Orders param)
{
} |
Kalai Sirajeddine.
Kalai Sirajeddine.
Kalai Sirajeddine.
Kalai Sirajeddine.
|
<ej-grid id="FlatGrid" allow-paging="true" allow-sorting="true" allow-scrolling="true" is-responsive="true" action-complete="complete" selected-row-index="3" databound="dataBound" row-selected="rowSelected" record-double-click="recordDoubleClick" toolbar-click="toolBarClick" export-to-excel-action="@Url.Action("ExportToExcel","Station")" export-to-pdf-action="@Url.Action("ExportToPdf","Station")">
<e-datamanager url="Station/StationData" remove-url="Station/Delete" adaptor="UrlAdaptor"></e-datamanager>
<e-page-settings current-page=3 page-size="5"> </e-page-settings>
<e-edit-settings allow-adding="true" allow-editing="true" allow-deleting="true" show-delete-confirm-dialog="true"></e-edit-settings>
<e-toolbar-settings show-toolbar="true" toolbar-items="@(new List<string>() {"add","edit","delete","update","cancel","excelExport","pdfExport" })"></e-toolbar-settings>
<e-columns>
<e-column field="Code" header-text="Code" text-align="Right" width="75" allow-editing="false"></e-column>
<e-column field="Description" header-text="Description" width="80"></e-column>
<e-column field="DistrictDescription" header-text="DistrictDescription" width="80"></e-column>
<e-column field="Id" header-text="" width="80" is-primary-key="true" visible="false"></e-column>
<e-column field="CreatedBy" visible="false"></e-column>
<e-column field="CreatedOn" visible="false"></e-column>
<e-column field="ConcurrencyID" visible="false"></e-column>
</e-columns>
</ej-grid>
|