我真的很难使用Controller服务加载jsGrid.我无法正确地做到这一点.
我甚至尝试了jsGrid站点演示中的示例代码,但是它也没有工作,它会在!this.data.length处抛出错误,或者网格根本不加载.
每次尝试使用下面的代码时,我都没有数据.
感谢是否有人可以提供帮助.
这是加载jsGrid的方式:
$(element).jsGrid({ height: 300,width: "100%",filtering: true,sorting: true,paging: true,autoload: true,pageLoading: true,controller: { loadData: function (filter) { $.ajax({ type: "GET",url: "../Common/GetData",data: filter,dataType: "JSON" }); } },pageSize: 10,pageButtonCount: 5,pageIndex: 1,noDataContent: "No Record Found",loadIndication: true,loadIndicationDelay: 500,loadMessage: "Please,wait...",loadShading: true,fields: [ { name: "Name",type: "textarea",width: 150 },{ name: "Age",type: "number",width: 50 },{ name: "Address",type: "text",width: 200 },{ name: "Country",type: "select" },{ name: "",width: 50,sorting: false,filtering: false,itemTemplate: function (value) { return '<div class="edit-container"><a class="edit-custom-field-link">Edit</a><div class="sort-icon-container"><div class="up-arrow-icon"></div><div class="down-arrow-icon"></div></div></div>'; } } //{ name: "Married",type: "checkBox",title: "Is Married",sorting: false } //,{ type: "control" } ] });
解决方法
你应该在加载数据时使用promises,
loadData: function(filter) { return $.ajax({ type: "GET",dataType: "JSON" }) }
return $.ajax({})返回Promise.是的,谢谢!