Search code examples
jqueryasp.net-mvc-4jqgridjqgrid-asp.netmvcjqgrid

mvcjqgrid custom sorting function not working


I am facing custom sorting issue with mvcjqgrid plugin.

As per my need column data should be sort in numerical order.

Column data = {M18, M2, M9, M1}, If i sort the column than column data should be shown as M1, M2, M9, M18 ....

What I have done : I have added one method into plugin to add line into jquery grid "sorttype:myCustomSorting" but javascript method is not calling.


`JavaScript function : 

function myCustomSorting(cell,obj){  
   //do something....  
}`

need some suggestion!!


Solution

  • Passing a function to sorttype is currently not supported on MvcJqGrid. Only the following values are allowed:

    https://github.com/robinvanderknaap/MvcJqGrid/blob/master/src/MvcJqGrid/Enums/SortType.cs#L8

    You could try to use OnSortCol on the grid itself:

    https://github.com/robinvanderknaap/MvcJqGrid/blob/master/src/MvcJqGrid/Grid.cs#L1114

    You can specify a custom sort function on this property. The function is raised immediately after a sortable column is clicked and before sorting the data.

    Pull-request is always welcome if you want to use sorttype ;) Shouldn't be too hard too implement.