asp.net mvc - durandal.js Sort by header issue -
i using durandal data grid rendering, clicking on columns header should sort result. problem having problem if there more 1 page data result, when click on next page, sorted result normal. please assist. thanks,
var searchterm = ko.observable(""); var pagination = { current: ko.observable(1), pages: ko.observablearray() }; var sortables = { barcode: { id: ko.observable('barcode'), active: ko.observable(true), asc: ko.observable(true) }, itemcode: { id: ko.observable('barcodemap.item.code'), active: ko.observable(false), asc: ko.observable(true) }, description: { id: ko.observable('barcodemap.item.description'), active: ko.observable(false), asc: ko.observable(true) }, quantity: { id: ko.observable('quantity'), active: ko.observable(false), asc: ko.observable(true) }, store: { id: ko.observable('store.name'), active: ko.observable(false), asc: ko.observable(true) }, fixture: { id: ko.observable('fixture'), active: ko.observable(false), asc: ko.observable(true) }, count: { id: ko.observable('count'), active: ko.observable(false), asc: ko.observable(true) }, createdby: { id: ko.observable('createdby'), active: ko.observable(false), asc: ko.observable(true) }, datecreated: { id: ko.observable('datecreated'), active: ko.observable(false), asc: ko.observable(true) } }; var filters = { store: ko.observable(null), count: ko.observable(null), user: ko.observable(null), fixture: ko.observable(null) }; var items = ko.observablearray(); var activate = function () { if (appsecurity.user().isauthenticated) { pagination.current(1); pagination.pages([]); // reset pagination return repo.getremote("stockid, barcode", breeze.predicate.create("barcode", breeze.filterqueryop.equals, null), pagination.current()) .then(function (obj) { items(obj.data); setpages(obj.inlinecount); }); } else return q.resolve(); }; var sort = function (id) { (var key in sortables) { sortables[key].active(false); } var sortable = sortables[id]; sortable.active(true); sortable.asc(!sortable.asc()); if (items().length > 0) { var local = repo.getlocally(sortable.id().concat(sortable.asc() ? "" : " desc"), getpredicate(), pagination.current()); if (local.length > 0) return items(local); } };
var changepage = function (page) { if (!indicator.isloading() && (page >= 1 && page <= pagination.pages().length && page != pagination.current())) { indicator.isloading(true); pagination.current(page); ko.utils.arrayforeach(pagination.pages(), function (item) { if (item.page() == page) item.active(true); else item.active(false); }); return repo.getremote("stockid, barcode", getpredicate(), pagination.current()) //[ch] .then(function (obj) { indicator.isloading(false); items(obj.data); }); } };
Comments
Post a Comment