This is a migrated thread and some comments may be shown as answers.

Kendo Grid Sort Compare

1 Answer 448 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Cherryln
Top achievements
Rank 1
Cherryln asked on 04 Mar 2019, 03:13 PM
Hi Guys,



I need to sort the column into alpha numeric using server side sorting.

The expected result would be like this below:

Test1

Test2

Test10

Test100



But the actual result becomes like this:

Test1

Test10

Test100

Test2



This can be sorted using sort compare in client side but on server side sorting, the sortCompare is always null.

Does anyone know how to properly sort this on server side?


Thanks

1 Answer, 1 is accepted

Sort by
0
Georgi
Telerik team
answered on 06 Mar 2019, 11:50 AM
Hi Cherryln,

A possible solution would be to add an additional property to the model which contains the same value as the alpha numeric field but the numeric part is padded.

e.g.

Test0000000001
 
Test0000000002
 
Test0000000010
 
Test0000000100

Model:

public string AlphaNumericField { get; set; } = "";
 
public string PaddedAlphaNumericField
{
    get
    {
        if (this.AlphaNumericField != null)
        {
            return Regex.Replace(this.AlphaNumericField, "[0-9]+", match => match.Value.PadLeft(10, '0'));
        }
 
        return this.AlphaNumericField;
    }
}

Then bind the column to that padded field and within the client template of the column display the original field.

e.g.

columns.Bound(x => x.PaddedAlphaNumericField).ClientTemplate("#=AlphaNumericField#");


Regards,
Georgi
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Tags
Grid
Asked by
Cherryln
Top achievements
Rank 1
Answers by
Georgi
Telerik team
Share this question
or