I have a SlickGrid table with multiple columns and I want the Index Column to be unaffected from sorting other columns.
I found this ancient question that is exactly describing the problem I'm having here, but the answer there didn't work for me. When I used this solution, my index column didn't return any values, it was just blank.
I tried if simply using a custom formatter would exlude the column from the sorting process, which it didn't. To do this, I copied "defaultFormatter" from here
function indexFormatter(row, cell, value, columnDef, dataContext) {
if (value == null) {
return "";
} else {
return (value + "").replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">");
}
};
PS: I thought it would be good to ask this in a new question rather than reviving the 9 year old one I linked earlier.
I think it's easiest to ignore the index column (this is, after all what SlickGrid uses to look up rows, so you don't want to mess with it) and just use the actual row number.
function indexFormatter(row, cell, value, columnDef, dataContext) {
return (row + 1) + '';
};
EDIT: whoops, I see that is just what the previous answer said too. Nonetheless, he was the creator of SlickGrid and I am one of the current maintainers, so give it a try! You may need the "+ ''" to convert to a string.