Sort broken
Sort broken
RemyHouard
Posts: 7Questions: 0Answers: 0
Hello,
I have a table with 4 fields of 2 different types I am trying to sort.
There are 3 dates with the format DD/MM/YYYY and the other a check box.
I get an error on table initialisation: Uncaught TypeError: Cannot call method 'fnSetData' of undefined - jquery.dataTables.min.js:29
This is the page where the table is malfunctioning (debug code 'oleguy'):
http://sistema.chezremy.com.br/?site=mm&do=playground&udo=data-tables-test
Any help would be greatly appreciated.
I have a table with 4 fields of 2 different types I am trying to sort.
There are 3 dates with the format DD/MM/YYYY and the other a check box.
I get an error on table initialisation: Uncaught TypeError: Cannot call method 'fnSetData' of undefined - jquery.dataTables.min.js:29
This is the page where the table is malfunctioning (debug code 'oleguy'):
http://sistema.chezremy.com.br/?site=mm&do=playground&udo=data-tables-test
Any help would be greatly appreciated.
This discussion has been closed.
Replies
Allan
[quote]This can occur when you have a different number of columns in the header, from those number in the body. ...[/quote]
Yeah I recognise the error when my table had an extra column. It's no longer the case as demosntrated here (without the aoColumns definition):
http://sistema.chezremy.com.br/?site=mm&do=playground&udo=data-tables-test-working
[quote]... Also if you use aoColumns or aoColumnDefs to supply information about columns which don't exist.[/quote]
So the problem lies in the aoColumns declaration. The table contais 20 columns and I declared 12 in aoColumns so it can't be that I declared too many...
Can you see anything wrong with it?
[code]
jQuery.extend( jQuery.fn.dataTableExt.oSort, {
'date-eu-pre': function ( date ) {
var date = date.replace(' ','');
if (date.indexOf('.') > 0) {
/*date a, format dd.mn.(yyyy) ; (year is optional)*/
var eu_date = date.split('.');
} else {
/*date a, format dd/mn/(yyyy) ; (year is optional)*/
var eu_date = date.split('/');
}
/*year (optional)*/
if (eu_date[2]) {
var year = eu_date[2];
} else {
var year = 0;
}
/*month*/
var month = eu_date[1];
if (month.length == 1) {
month = 0+month;
}
/*day*/
var day = eu_date[0];
if (day.length == 1) {
day = 0+day;
}
return (year + month + day) * 1;
},
'date-eu-asc': function ( a, b ) {
return ((a < b) ? -1 : ((a > b) ? 1 : 0));
},
'date-eu-desc': function ( a, b ) {
return ((a < b) ? 1 : ((a > b) ? -1 : 0));
}
} );
/* Create an array with the values of all the input boxes in a column */
$.fn.dataTableExt.afnSortData['dom-text'] = function ( oSettings, iColumn )
{
return $.map( oSettings.oApi._fnGetTrNodes(oSettings), function (tr, i) {
return $('td:eq('+iColumn+') input', tr).val();
} );
}
/* Create an array with the values of all the select options in a column */
$.fn.dataTableExt.afnSortData['dom-select'] = function ( oSettings, iColumn )
{
return $.map( oSettings.oApi._fnGetTrNodes(oSettings), function (tr, i) {
return $('td:eq('+iColumn+') select', tr).val();
} );
}
/* Create an array with the values of all the checkboxes in a column */
$.fn.dataTableExt.afnSortData['dom-checkbox'] = function ( oSettings, iColumn )
{
return $.map( oSettings.oApi._fnGetTrNodes(oSettings), function (tr, i) {
return $('td:eq('+iColumn+') input', tr).prop('checked') ? '1' : '0';
} );
}
$('#admin-financeiro-lancamento-search-return').dataTable({
'bPaginate': false
,'bJQueryUI': true
,'sPaginationType': 'full_numbers'
,'oLanguage': {
'sUrl': '/inc/DataTables/pt-br.txt'
}
,'aoColumns': [
null,
null,
null,
null,
null,
null,
{ 'sSortDataType': 'dom-checkbox' },
null,
{ 'sSortDataType': 'date-eu' },
{ 'sSortDataType': 'date-eu' },
null,
{ 'sSortDataType': 'date-eu' }
]
,'bPaginate': false
,'bStateSave': false
,'sDom': '<"top"<"clear">>rt<"bottom"iflp<"clear">>'
,'aaSorting': [[0,'desc']]
});
[/code]
You need to specify aoColumns accurately if you are going to use it. If you want to specify options for only some columns, use the aoColumnDefs option and target the columns you want (for example you could add a class to those you want to be EU date sorted).
Allan
Ok so define all columns in aoColumns. Did that, completed them with null.
I no longer get an error and checkbox sorting works like a charm.
However date is still sorting as string instead of date.
I'm using the function in my previous post taken from the plugins page.
Is that the correct code to use?
I updated the example page and debug code: uresuy
Thanks again