Datatables: Custom types
I am having some problems creating custom types for my data table, using jquery.datatables.js.
My table initialization looks like this:
drawTable['#<?= $tab ?>'] = function() {
$('#sites_<?= $tab ?>').dataTable({
'iDisplayLength' : 25,
'aaSorting': [[5, 'desc']],
'aLengthMenu': [[25, 50, 100, -1], [25, 50, 100, 'All']],
'aoColumns' : [
{'sType' : 'formatted-num'},
null,
null,
null,
{'sType' : 'formatted-num'},
{'sType' : 'formatted-num'},
{'sType' : 'formatted-num'},
{'sType' : 'formatted-num'},
{'sType' : 'formatted-num'},
{'sType' : 'formatted-num'}
]
})
};
And then:
$(document).ready(function() {
drawTable['#<?= $tab ?>']();
drawnTable['#<?= $tab ?>'] = true;
});
The $tab is to select some values from server.
That works well for the custom types, but I need to create my own type. How do I do so? I have been reading some of the examples here: http://www.datatables.net/plug-ins/type-detection but all of them seem to be done for tables started with only $(document).ready(function() {
$('#example').dataTable();
} );
Not really sure how to implement at least one of those to one of my columns, if I could at least do that I would just write my own fun开发者_如何转开发ction. Thanks!
This is how it is done:
jQuery.fn.dataTableExt.oSort['num-html-asc'] = function(a,b) {
a = ;//changes to remove html signs
b = ;//same as above
return ((a < b) ? -1 : ((a > b) ? 1 : 0));
};
jQuery.fn.dataTableExt.oSort['num-html-desc'] = function(a,b) {
a = ;//changes to remove html signs
b = ;//same as above
return ((a < b) ? 1 : ((a > b) ? -1 : 0));
};
Include that function after including datatables.js, but before initializing it. Then in the column that needs to use that
{'sType' : 'num-html'},
That's all.
精彩评论