How to sort numeric values ​​with string values ​​in Kendo-Grid

I am using a Kendo-Grid, which has a column that has values ​​of both numbers and rows (NA). Any idea to sort them?

+6
source share
4 answers

Works with avilable code at http://jsbin.com/egoneWe/3/edit

+1
source

You can sort them using a custom comparison function. Here is an example of code that places elements with 'N / A' on top:

$("#grid").kendoGrid({ dataSource: [ { price: 1 }, { price: "N/A" }, { price: 20 }, { price: 2 } ], sortable: true, columns: [ { field: "price", sortable: { compare: function(a, b) { var x = a.price; var y = b.price; if (x == 'N/A') { x = 0; } if (y == 'N/A') { y = 0; } return x - y; } } } ] }); 

Here is a live demo: http://jsbin.com/urUXOCa/1/edit

+6
source

Enter the field values ​​as numbers. Then, if necessary, add a line during the display.

Please ask for help: do not sort the sort numbers (dollar and percentage)

0
source

As far as I know, there is no way to create your own sort function for the field. I found http://sympletech.com/how-to-enable-case-insensitive-sorting-on-kendo-ui-grid/ where someone implemented something like what you are asking (he just did random sorting).

I had to do this once (fortunately, on an uneditable grid, I just showed the data), and I just sorted the grid using the template. Going through the data before it was a dataBound, adding another property to it that represented the data that would be sorted properly, and tying the grid to this column instead of the original column, but using a template that returned the original data value.

See jsbin http://jsbin.com/ETaZOSu/1/edit

0
source

Source: https://habr.com/ru/post/954632/


All Articles