jquery - Saving Kendo Grid sort to a database in javascript -
i using kendo grid display client data. following code generates grid.
$(document).ready(function() { var grid = $("#clientsdb").kendogrid({ datasource: { pagesize: 20, serverpaging: true }, groupable: true, sortable: true, pageable: true, scrollable: false }).data("kendogrid"); grid.table.kendosortable({ filter: ">tbody >tr", hint: $.noop, cursor: "move", placeholder: function(element) { return element.clone().addclass("k-state-hover").css("opacity", 0.65); }, container: "#grid tbody", change: function(e) { var skip = grid.datasource.skip(), oldindex = e.oldindex + skip, newindex = e.newindex + skip, data = grid.datasource.data(), dataitem = grid.datasource.getbyuid(e.item.data("uid")); grid.datasource.remove(dataitem); grid.datasource.insert(newindex, dataitem); } }); });
the bottom half of javascript code sorts rows in table. having trouble figuring out how save sort database. assume can post db using ajax, unsure how can written.
to store row order can add in change handler:
//assuming id uniquely identifies row in database $.post("@url.action("updateindex")", { id: dataitem.id, index:newindex });
server-side need store data against index/order column. grid can sorted on index/order column , reflect changes made on client side.
Comments
Post a Comment