javascript - paging not moving to new data in kendogrid -
please note @ time new asp.net mvc, javascript , kendo. kendo grid paging works first 500 records returned, won't allow paging download more data server past 500. here controller:
public actionresult executetestrule(string ruleid, string rulesql, string uwi, list<pdsmatchruleparam> parameters = null) { if (request.url != null) { var query = paginationquery.parse(request.querystring); var upperlimit = query.fromupper; var lowerlimit = query.fromlower; var datasource = new matchdatasource(); list<dataaccess.dbparameter> dbparameters = null; var generatedsql = datasource.generatequerysql(ruleid, rulesql, uwi, parameters, out dbparameters); var results = datasource.executetestrule(ruleid, generatedsql, dbparameters, upperlimit, lowerlimit).select(u => new { uwi = u }); var response = new dictionary<string, object>(); response["result"] = results; response["rowcount"] = matchdatasource.getrowcount(generatedsql, dbparameters); return json(response, jsonrequestbehavior.allowget); } return null; }
here total number of rows available "rowcount" in controller:
matchdatasource.getrowcount(generatedsql, dbparameters) 91637
here request.querystring in controller:
request.querystring {} [system.web.httpvaluecollection]: {} base {system.collections.specialized.nameobjectcollectionbase}: {} allkeys: {string[0]}
pressing button has no effect:
here javascript code:
function bindtestruleresults() { pagestate.selected.old.testruleresult = pagestate.selected.testruleresult; var datasource = new kendo.data.datasource({ pagesize: 500, data: pagestate.selected.testruleresult, serverpaging: true }); grids.testruleresultsgrid.setdatasource(datasource); pagestate.selected.testruleresult = null; } function inittestruleresultsgrid() { $(ids.testruleresultsgrid).kendogrid({ autobind: true, filterable: false, navigatable: true, pageable: { refresh: true, pagesizes: [10, 50, 100, 500], buttoncount: 5 }, scrollable: true, selectable: true, serverfiltering: false, serverpaging: true, serversorting: true, sortable: false, columns: [ { field: "uwi", title: "uwi", width: "100%", attributes: { tabindex: "1" } } ], change: function() { var selecteddataitem = this.dataitem(this.select()); if (pagestate.selected.testruleresult !== selecteddataitem.testruleresult) { pagestate.selected.testruleresult = selecteddataitem.testruleresult; testruleresultsselectionchanged(); } }, editable: false }); // add vertical scroll bars $(ids.testruleresultsgrid + " .k-grid-content").css({ "overflow-y": "scroll" }); grids.testruleresultsgrid = $(ids.testruleresultsgrid).data('kendogrid'); } function exectestrule(uwi) { $.ajax({ type: 'post', url: "executetestrule", contenttype: 'application/json; charset=utf-8', data: json.stringify({ ruleid: pagestate.selected.ruleid, rulesql: pagestate.sqleditor.rulesql.getvalue(), uwi: "'" + uwi + "'", parameters: pagestate.ruleparameters }), schema: { errors: function(response) { return response.error; }, data: function(response) { return response.result; }, total: function(response) { return response.rowcount; } }, success: function(matcheduwilist) { pagestate.testruleresult = matcheduwilist.result; var datasource = new kendo.data.datasource({ pagesize: 500, data: matcheduwilist.result, serverpaging: true }); grids.testruleresultsgrid.setdatasource(datasource); pagestate.selected.childuwi = null; updatebuttonstates(); }, error: function(e) { var errorobject = json.parse(e.xhr.responsetext); var errormessage = errorobject.message; //clear old error message grids.testruleresultsgrid.clearerrormessage("error-message"); // add new error message grids.testruleresultsgrid.adderrormessage("error-message", errormessage); } }); }
it has serverpaging = true in data source. missing? need somehow make pagesize dynamic in javascript code? tia.
update:
thank feedback, @brett. how i've simplified code suggested. how remove success: function outside of ajax part?
function exectestrule(uwi) { $.ajax({ type: 'post', url: "executetestrule", contenttype: 'application/json; charset=utf-8', data: json.stringify({ ruleid: pagestate.selected.ruleid, rulesql: pagestate.sqleditor.rulesql.getvalue(), uwi: "'" + uwi + "'", parameters: pagestate.ruleparameters }), success: function(matcheduwilist) { pagestate.testruleresult = matcheduwilist.result; var datasource = new kendo.data.datasource({ schema: { data: 'results', total: 'rowcount' }, pagesize: 500, serverpaging: true }); grids.testruleresultsgrid.setdatasource(datasource); pagestate.selected.childuwi = null; updatebuttonstates(); } }); }
when exectestrule function run, error i'm getting:
you code confusing me, see 1 particular problem. not telling kendo ui datasource data , row count properties in returned object controller.
in controller, specify data located in response["results"]
property, while row count in response["rowcount"]
property. therefore, returned object looks this:
{ results: [...], rowcount: 91637 }
the kendo ui datasource object's schema
, default, expects data located in "data"
property , row count (a.k.a. number of items in data) located in "total"
property. since object not conform convention, need tell data source properties named differently.
var datasource = new kendo.data.datasource({ schema: { data: 'results', total: 'rowcount' }, pagesize: 500, serverpaging: true });
so, might doing already, defined it. defined on $.ajax()
call. not correct. $.ajax()
function not care schema
. kendo ui datasource does.
Comments
Post a Comment