Type Error | pagination: jumpToData current date or later
Type Error | pagination: jumpToData current date or later
I am trying to show the datatables on the right page (pagination) with the current date or later with the help of the jumpToData() function, e.g. today is the 2016-08-08. The page of the datatables should automatically (when finished loading) be set on this date (column 0). If the date is not available it should jump to the page with the next date available. So far I have this code:
jQuery.fn.dataTable.Api.register( 'page.jumpToData()', function ( data, column ) {
var pos = this.column(column, {order:'current'}).data().indexOf( data );
var followingdays = 0;
while(pos == -1 && followingdays < 10){
var day = (parseInt(data.subString(8))+1);
if(day > 31){ //wenn >31 monatswechsel
day = "01";
var month=parseInt(data.subString(5,7))+1;
var year = parseInt(data.subString(0,4));
if(month < 10){
month = "0" + month.toString();
} else if(month > 12){
year = year + 1;
}
data = year.toString() + "-" +month + "-" + day;
}else if(day < 10){
day = "0" + day.toString();
data = data.substring(0,8) + day;
}else{
data = data.substring(0,8) + day;
}
pos = this.column(column, {order:'current'}).data().indexOf( data );
followingdays++;
}
if ( pos >= 0 ) {
var page = Math.floor( pos / this.page.info().length );
this.page( page ).draw( false );
}
return this;
} );
This is a workaround however since I just look at the current date plus the following 10 days and not the general future of the current date. I can live with that for now hence my first question is that I get a TypeError in the line.
var day = (parseInt(data.subString(8))+1);
and I dont know why. data.subString(8)
should be '08' in the example given. data
is correct: '2016-08-08'. The jumpToData() is called in my initComplete method of the datatables:
"initComplete": function(settings, json) {
var ftable = $('#table_fuehrungen').DataTable();
var today = new Date();
var dd = today.getDate();
var mm = today.getMonth()+1; //January is 0
var yyyy = today.getFullYear();
if(dd<10) {
dd='0'+dd
}
if(mm<10) {
mm='0'+mm
}
today = yyyy+"-"+mm+"-"+dd;
ftable.page.jumpToData( today, 0 );
},
Thus my first question is why there is a TypeError on the given line and the second quesion is how do I code it better to jump to the page with the generic future of the current date?
I am using DataTables 1.10.12.
This question has an accepted answers - jump to answer
Answers
The type error suggests that
data
is not a string. You definetoday
initially as aDate
object and then change it to be a string, which I think should work, but really I'd need a link to a page showing the issue to I can debug it.Allan
Thanks for the link via e-mail.
The issue is there there is no
subString
method in Javascript it is calledsubstring
(note the case).Allan