mData, mRender and ordering
mData, mRender and ordering
giorgioponza
Posts: 3Questions: 0Answers: 0
Hello, i'm trying to port my 'old' 1.8 datatables to new 1.9.
The table is populated by Ajax and the source is JSON. Each row is defined as follow:
[code]{"date":"17.06.12 10:49:26","id":166,"odometer":4560}[/code]
I define the 'odometer' column in 'aoColumnDefs' with the "mData": "odometer". In this way, if i order by 'odometer' column, everything is working ok. If i add a "mRender" like this
[code]"mRender": function (data, type, full) { return addCommas(data, '.', ','); }[/code]
then the order is done using the RENDERED cell value and not the raw one [addCommas simply adds thousand separator for easy reading, but in italy the char used is . and this is the decimal separator for english].
Before 1.9, i used the "bUseRendered" option, but now is deprecated. If i've readed right the docs, the field on which the order is done should be the one defined with "mData", because "mRender" is only used for showing the raw value in a different way.
So my question is: why the order is done using the value in 'mRender' and not the one in 'mData' ? Am i missing some configuration?
I prepared a small test on this page http://nasar.movimatica.com/Test.jsp. The second table has a wrong order on column 'odometer'
Thank you so much
Giorgio Ponza
The table is populated by Ajax and the source is JSON. Each row is defined as follow:
[code]{"date":"17.06.12 10:49:26","id":166,"odometer":4560}[/code]
I define the 'odometer' column in 'aoColumnDefs' with the "mData": "odometer". In this way, if i order by 'odometer' column, everything is working ok. If i add a "mRender" like this
[code]"mRender": function (data, type, full) { return addCommas(data, '.', ','); }[/code]
then the order is done using the RENDERED cell value and not the raw one [addCommas simply adds thousand separator for easy reading, but in italy the char used is . and this is the decimal separator for english].
Before 1.9, i used the "bUseRendered" option, but now is deprecated. If i've readed right the docs, the field on which the order is done should be the one defined with "mData", because "mRender" is only used for showing the raw value in a different way.
So my question is: why the order is done using the value in 'mRender' and not the one in 'mData' ? Am i missing some configuration?
I prepared a small test on this page http://nasar.movimatica.com/Test.jsp. The second table has a wrong order on column 'odometer'
Thank you so much
Giorgio Ponza
This discussion has been closed.
Replies
[code]
"mRender": function (data, type, full) {
if ( type === 'display' ) {
return addCommas(data, '.', ',');
}
return data;
}
[/code]
With that the unformatted data will be used for sorting, filtering and type detection, while the formatted data will be used for display only. You can modify the function as you wish to use other options as well. See: http://datatables.net/blog/Orthogonal_data
Allan
With your help, now it works as expected.
Many many thanks
I used to use "bUseRendered" along with "fnRender" to display something different to the underlying data in the table, but use the original data when exporting to file with TableTools. I tried using the code that Allen has suggested above, expecting it to work as before, but TableTools will render the cell data as it is displayed in the table. Any Ideas how I can fix this to use only the pre-rendered data for TableTools? I have tried both mData and mRender.
Thanks
Allan