PDA

View Full Version : Sorting in GridPanel doesnt work on Column which contains blank value



livinglegends
22 Sep 2010, 3:51 AM
Hi,

In my grid panel, I have 4 columns say C1 to C4.
C1 to C3 column contains value in each row but in C4 column, some values are blank.

When, I perform sorting on C4 (by clicking on column header or by selecting Asc or Desc order from the header menu), sorting doesn't work.

So, how to resolve this issue?

Thanks and Regards
Living Legend

laurentParis
22 Sep 2010, 4:17 AM
C4 using renderer method ?
you must to know that sort method work with store, not with grid !

livinglegends
22 Sep 2010, 4:21 AM
C4 using renderer method ?
you must to know that sort method work with store, not with grid !

I didnt get ur question. Renderer method means?
Can u give one code sample?

FlaminPhoenix
22 Sep 2010, 4:27 AM
laurent was asking you if you were using a renderer for your column causing it not to sort. for example

new Ext.grid.GridPanel(...
cm:[....
renderer:function(value){
// Do something with value here, and return a HTML IMG tag or anything that you want to change in a column based on
// the values in store
}
]);

Are you doing this?

livinglegends
22 Sep 2010, 4:30 AM
No...we are not using any renderer method.

laurentParis
22 Sep 2010, 4:33 AM
So, can you give me an example of datas list for C4 column. thanks

livinglegends
22 Sep 2010, 4:39 AM
We are getting data from the server in JSON format and using following code to set data.

The following code we are using to send AJAX request to server which returns data in JSON and
setting to store.




Ext.Ajax.request({
url : "URL",
params : "List of parameters",
success : function(response, opts) {
var json = Ext.decode(response.responseText);
if (!Ext.isEmpty(json)) {
store.loadData(json);
}
},
failure : searchFailure
});

laurentParis
22 Sep 2010, 4:43 AM
sorry, you missunderstanding
I prefer the simple data list example like this :


* C4 *
one
two

five
seven


ten
one
two
two

tree

livinglegends
22 Sep 2010, 4:49 AM
You can take your data as a sample. I found one new thing is that, actually it does sorting but between group of value.

In your example,

It is doing sorting between "one and two", between "five and seven", between "ten, one, two, tow" and tree is alone so kept at it is.

Means sorted list would be



one
two

five
seven

one
ten
two
two

tree


I feel that blank value actually comes From JSON as a null and store doesnt treat null in sorting properly. I have manually added some rows with value undefined instead of null so it is working fine.
Hope, I am cleared now.

livinglegends
22 Sep 2010, 5:15 AM
waiting for your reply laurent

laurentParis
22 Sep 2010, 5:31 AM
I believe that you found solution by yourself !! :)
With this information I have no more idea, sorry... for me, if you have some trouble with sorting action, is because the datas you try to sort are on error (format, type, value)

livinglegends
22 Sep 2010, 6:33 AM
Can anybody tell me how to resolve issue of sorting column when column contains null value?

laurentParis
22 Sep 2010, 7:02 AM
heu modify your server code to replace null value by blank value !

troseberry
22 Sep 2010, 7:08 AM
I just tried this with some basic sample data and a grid setup for sort. I also found that it is an issue with explicit 'null' values. if they are blank then it works fine.

troseberry
22 Sep 2010, 7:26 AM
If you can't get the server to fix the value then you can do something like this.

In your store's field definition setup on the field a "convert" parameter and then setup a function that will check for null and pass back an empty string.
This was adapted to the Array-Grid example



function fixNull(v, record){
if(Ext.isEmpty(record[0]))
{
return '';
}
else
{
return record[0];
}
}
// create the data store
var store = new Ext.data.ArrayStore({
fields: [
{name: 'company', convert: fixNull},
{name: 'price', type: 'float'},
{name: 'change', type: 'float'},
{name: 'pctChange', type: 'float'},
{name: 'lastChange', type: 'date', dateFormat: 'n/j h:ia'}
]
});