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

Sorting in Grid for Combo field

1 Answer 621 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Salim
Top achievements
Rank 1
Salim asked on 28 Jun 2018, 12:00 PM
How can we change the sorting behavior on the Grid and make it sort by combo text field instead of value field?

I have a combo column, the value field is the id and the text field of the combo is loaded after getting the data of the combo
When sorting the sort is done by id which produce a wrong layout (because text is shown on the grid and not the id )

How can I solve this issue?

1 Answer, 1 is accepted

Sort by
0
Accepted
Dimiter Topalov
Telerik team
answered on 02 Jul 2018, 07:54 AM
Hi Salim,

Typically the Grid will sort its data by the field the respective column is bound to. To sort the Grid data by a text field that presumably is not yet available (as a part of the Grid data or otherwise), you will need to prefetch all objects that are related to the ComboBoxes and either map the Grid data such that it receives a complex object field (like the categories in our online demos) or otherwise relate the Grid data items to the respective objects' text fields so that the Grid data can be sorted by this text field.

Mapping the Grid data beforehand will also make it easier to bind the respective Grid column directly to the text field of the complex objects (that will be already part of the Grid data), e.g.:

https://plnkr.co/edit/HgqOLOss0DxdzcZ9m4ZY?p=preview

Alternatively, you will need an array of objects associating a CategoryID (or other foreign key) Grid field to the respective text, so that you can perform the custom sorting in the sortChange event handler - for example:

https://plnkr.co/edit/c6k5f4P6Nj08Jg0pm73P?p=preview

I hope this helps.

Regards,
Dimiter Topalov
Progress Telerik
Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Tags
General Discussions
Asked by
Salim
Top achievements
Rank 1
Answers by
Dimiter Topalov
Telerik team
Share this question
or