Thread ID: |
Created: |
Updated: |
Platform: |
Replies: |
144548 | May 11,2019 07:21 AM UTC | Jun 19,2019 08:48 AM UTC | JavaScript - EJ 2 | 7 |
![]() |
Tags: Grid |
class CustomAdaptor extends UrlAdaptor {
beforeSend(dm: DataManager, request: XMLHttpRequest): void {
request.setRequestHeader("Authorization", "bearer");
}
processQuery(dm: DataManager, query: Query, hierarchyFilters?: Object[]): Object{
return {
// send query based on your service
};
}
}
this.data = new DataManager({
url: 'api/Orders/DataSource',
insertUrl: "api/Orders/Insert",
updateUrl: "api/Orders/Update",
removeUrl: "api/Orders/Delete",
adaptor: new CustomAdaptor
}); |
var isEssential = true;
ej.grids.Grid.Inject(ej.grids.Page);
grid = new ej.grids.Grid({
dataSource: { result: [], count: 0 },
dataStateChange: function (args) { // dataStateChage event of Grid can triggered in every data change of Grid
getData(args.skip, args.take); // you can execute your service with page queries.
},
dataSourceChanged: function (args) {
getData(args); // in here you can execute your service while perform the CRUD actions.
},
allowPaging: true,
load: load,
columns: [
{ field: 'EmployeeID', headerText: 'EmployeeID', width: 160 },
{ field: 'CustomerID', headerText: 'CustomerID', width: 160 },
{ field: 'ShipCity', headerText: 'ShipCity', width: 160 }
],
height: "100%",
});
grid.appendTo('#Grid');
function load() {
if (isEssential) {
var obj = document.getElementById("Grid").ej2_instances[0];
var pageSize = obj.pageSettings.pageSize;
var currentPage = 0;
page = getData(pageSize, currentPage); // inital load need to generate skip and take query based on Grid pageSettings
}
}
function getData(skip, take) {
// skip and take queries handle the on-demand loading concept
// you can execute your service with skip and take queries
//once if you get a data from your service you can bind the json data into Grid as below way.
// please handle the CURD actions here
var grid = document.getElementsByClassName("e-grid")[0].ej2_instances[0];
grid.dataSource = { result :data, count: count }; // you need bind the data into grid in this way. Count specifies the total number of record. So you need to return your whole data count from server.
} |
This post will be permanently deleted. Are you sure you want to continue?
Sorry, An error occured while processing your request. Please try again later.
This page will automatically be redirected to the sign-in page in 10 seconds.