caloggins
7/18/2016 - 2:06 PM

ko.sorting.js

define(["knockout", "toastr"], function(ko, toast) {
  ko.bindingHandlers.sort = {
    init: function (element, valueAccessor, allBindingsAccessor, viewModel, bindingContext) {
      // it's a good idea to have this opposite of the default in the view model
      var asc = true;
      element.style.cursor = "pointer";

      element.onclick = function () {
        var value = valueAccessor();
        var prop = value.prop;

        asc = !asc;

        viewModel.sortDirection(asc ? "ASC" : "DESC");
        viewModel.sortColumn(prop);
        viewModel.loadData();
      };
    }
  };
})