sort the column with rated attributes in datatables
I have to sort the rated data column in the datatable. The rated data contains star as the rating out of 5. the data is coming properly but it is not getting sorted. i m using theme roller css in datatables and data table is created with following code.
$('#data_table').dataTable( {
"aaData": dataSet ,
"bSort":true,
"aaSorting": [[0,'desc'],[0,'asc'],[2,'asc'],[2,'desc']],
"iDisplayLength": 4,
"bInfo": true,
"bLengthChange": false,
"bJQueryUI": true,
"bPaginate": true,
"bAutoWidth": false,
"sPaginationType": "full_numbers",
"bAutoWidth": true,
"aoColumns": [
{ "sTitle": "Seller",
"sWidth": "155px",
"sClass": "grey" ,
"fnRender": function(obj) {
var data = obj.aData[ obj.iDataColu开发者_StackOverflow社区mn ];
return "<a href='"+ data.url +"'>"+ data.title +"</a>";
}
},
{
"sTitle": "Seller rating",
"sClass": "center grey",
"sWidth": "100px",
"fnRender": function(obj) {
var sReturn = obj.aData[ obj.iDataColumn ];
var val = obj.aData[ obj.iDataColumn ];
if ( sReturn != "N/A") {
$('#fixed').raty({
readOnly: true,
start: val
});
sReturn = $('#fixed').html();
$('#fixed').html("");
}
return sReturn;
}
})
I want the seller rating column which is the rated column using star as the image. to be sorted according to the star it has.
bUseRendered (columns)
When using fnRender() for a column, you may wish to use the original data (before rendering) for sorting and filtering...
EDIT
"aaSorting": [[0,'desc']],
"aoColumns": [
{
"mDataProp": "timestamp",
"fnRender": function ( oObj ) {
return "do whatever you need...";
},
"bUseRendered": false
},
null
]
I think you should change the part:
"aaSorting": [[0,'desc'],[0,'asc'],[2,'asc'],[2,'desc']],
with
"aaSorting": [[1,'desc']],
Then it will sort the table according to second column's values and if you can give us some of the rows from your dataset then we can answer your question better if something is missing in my answer.
精彩评论