Preventing some rows from being sorted.

Hi,

I have a datatable that provides sort function. If I sort the data, I want to sort only few rows(not all the rows in the datatable). How can I do this?

Please help me!!!

Thank you.

Hi,

You can customize a sorting function and define the logic you need:

function sortByRank(a, b){
   // a, b - data item objects that are compared
   ...
}
webix.ui({
  view:"datatable",
  columns:[
    { id:"votes",	header:"Votes",  width:100, sort:sortByRank}
  ]
});

http://webix.com/snippet/75745b43

You can as well study the following sample for details: http://docs.webix.com/samples/15_datatable/02_sorting/03_sort_api.html

Thanks a lot Helga.
In the below function,
function sortByRank(a,b){
if(a.id<3) return;
a = a.rank;
b = b.rank;
return a>b?1:(a<b?-1:0);
}

Can I call the default sort function after “if(a.id<3) return;”?
Please tell me how I can do that…

I need to sort by all the columns, but I should retain few rows at the top.

Hello,

Can I call the default sort function

Could you please explain what is default sorting function ? Sorting function is set in the “sort” property. It can be either one of built-in functions: “string”, “int”, etc., or a custom function that returns 1,-1 or 0 value. Try to use the approach recommended by Helga. And if it does not fit your requirements, you can use own solution. Here you can find detailed information about sorting function:
http://docs.webix.com/datatable__sorting.html#customsortingfunctions