I have been working on organizing my grid and here is the code that I have so far:
ko.moveInGrid = {
// Creating a view model class for grid population
viewModel : function(config) {
this.data = config.data;
this.currentPageIndex = ko.observable(0);
this.pageSize = config.pageSize || 5;
// If columns configuration is not specified, scaffolding will be used
this.columns = config.columns
|| getColumnsForScaffolding(ko.utils
.unwrapObservable(this.data));
this.actions = config.actions;
this.itemsOnCurrentPage = ko.computed(function() {
var startIndex = this.pageSize * this.currentPageIndex();
return this.data.slice(startIndex, startIndex + this.pageSize);
}, this);
this.maxPageIndex = ko.computed(function() {
return Math.ceil(ko.utils.unwrapObservable(this.data).length
/ this.pageSize) - 1;
}, this);
this.sortByName = function() {
console.info(config.columns);
console.log("this works");
config.sort(function(a, b) {
return a.name < b.name ? -1 : 1;
});
};
}
};
Here is how I am invoking my function
<th data-bind=\"click: $root.sortByName,attr:{'data-translate': headerText}\" class=\"sorting\"></th>\
My ViewModel
seems to be correct. However, when I click on the header, I encounter the following error message:
TypeError: config.sort is not a function