Sort by display value in ExtJS 3 EditorGridPanel

I am new to Ext, so I apologize in advance if my question is not clear enough / too basic ...

I have Ext.grid.EditorGridPanel with Ext.data.Store and Ext.data.JsonReader.

I have the following problem:

I would like to make the columns in my grid sortable, but the value returned from my store is not the value I would like to sort (the return value is an identifier, and I would like to sort this ID-card by line).

I have a rendering function that converts this identifier and string value, but I don't know how to integrate it into my code.

I found this post:

http://www.sencha.com/forum/showthread.php?45324-Grid-column-sorting-on-rendered-value

which looked like my need, but when I tried to add:

{name: 'my_field', sortType: my_render_function} 

For my JsonReader, this did not work.

Where am I mistaken?

Thanks.


To request Pater:

 var my_render = function(val, metaData, record, rowIndex, colIndex, store){ if (val == null) return ''; var n = another_store.getById(val); if (n == null) return ''; return n.data.name; }; var my_reader = new Ext.data.JsonReader({ root: 'my_root', id: 'tissue_num', }, [{ name: 'tissue_num', type: 'int' }, 'tissue_desc', 'organ'] ); var my_store = new Ext.data.Store({ url: request_url, baseParams: { _state: request_state, _action: 'get_conditions' }, sortInfo: { field: 'tissue_num', direction: "ASC" }, reader: my_reader, pruneModifiedRecords: true }); 
+4
source share
1 answer

Since you need something more than just a mapping transformation, I would not use a visualization tool here, but instead convert data into a record definition.

 val convertName = function(val, rec) { // val will always be null since there no field named 'name' var id = rec.data.tissue_num; if (id == null) return ''; var n = another_store.getById(id); if (n == null) return ''; return n.data.name; }; var my_reader = new Ext.data.JsonReader({ root: 'my_root', id: 'tissue_num', }, [{ name: 'tissue_num', type: 'int' }, {name: 'name', convert: convertName}, 'tissue_desc', 'organ'] ); 

This will give you a record with the data in the name field, where you can do everything you would do with the actual data received from the server; sorting, filtering, displaying, etc. Easier than trying to print the displayed value every time you need it.

+3
source

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


All Articles