Few Problems
Few Problems
Ant248
Posts: 15Questions: 3Answers: 0
Hi,
Having a few problems.
Firstly two errors in my console log:
SCRIPT5007: Unable to get property 'defaults' of undefined or null reference
File: dataTables.jqueryui.js, Line: 47, Column: 1
and
SCRIPT5007: Unable to get property 'mData' of undefined or null reference
File: jquery.dataTables.min.js, Line: 92, Column: 490
the second when i use this code to initialise:
$(document).ready(function() {
$('#maintable').DataTable( {
"columnsDefs": [
{ "targets": 1, "orderDataType": "dom-text-numeric",},
{ "targets": 2, "orderDataType": "dom-select" },
{ "targets": 3, "orderDataType": "dom-select" },
{ "targets": 4, "orderDataType": "dom-select" },
{ "targets": 5, "orderDataType": "dom-select" },
{ "targets": 6, "orderDataType": "dom-select" },
{ "targets": 7, "orderDataType": "dom-text-numeric" },
{ "targets": 8, "orderDataType": "dom-text-numeric" },
{ "targets": 9, "orderDataType": "dom-text-numeric" },
{ "targets": 10, "orderDataType": "dom-text-numeric" },
{ "targets": 11, "orderDataType": "dom-text-numeric" },
{ "targets": 12, "orderDataType": 'number' },
{ "targets": 13, "orderDataType": 'number' },
{ "targets": 14, "orderDataType": 'number' },
{ "targets": 15, "orderDataType": 'number' }
],
"aoColumns":[
{ "sType": "date-uk" },
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null
]
} );
});
I'm trying to sort a date in the format of yyyy-mm-dd i'm using the plugin (slightly modified):
jQuery.extend( jQuery.fn.dataTableExt.oSort, {
"date-uk-pre": function ( a ) {
var ukDatea = a.split('-');
return (ukDatea[0] + ukDatea[1] + ukDatea[2]) * 1;
},
"date-uk-asc": function ( a, b ) {
return ((a < b) ? -1 : ((a > b) ? 1 : 0));
},
"date-uk-desc": function ( a, b ) {
return ((a < b) ? 1 : ((a > b) ? -1 : 0));
}
} );
however i get the error message a cannot be spit.
Also last quick question, my dynamically calculated values do not sort.
Are they not picked up the same way as form inputs?
Thanks,
Ant
This discussion has been closed.
Answers
First, you need to use only one, "columnDef" or "aoColumns", as they ultimately serve the same function.
Second, if you use "columnDef", "targets" starts at 0.
Third, the "-asc" and "-desc" will never fire since you included "-pre", but luckily in your case you don't need them and can just use "-pre".
Make these changes and let me know if it resolves your issue.
Here is a link to a discussion discussing "-pre", "-asc", "-desc", and an explanation of their function and relationship by Allan.
http://datatables.net/forums/discussion/comment/88294/#Comment_88294
Sounds like you might be loading jQuery twice on your page or loading the integration file before the main DataTable file. Without a test case it is difficult to say more though.
Allan
Thanks for the replys,
ok i have fixed the default error was the dataTables.jqueryui.js being loaded before the dataTables script.
I have edited my initialization to:
however now the table doesn't work at all :(
i'm still getting:
these are are the scripts im loading:
many thanks
Ok got it to work now.. hadn't set null for the rest of the columns:
no errors on mData.
although when i click the sort button with the date inputs i get:
the line its referring to is the:
in
anyone have any ideas?
ukDatea comes up as undefinied
We'd need a link to a test page showing the issue. It suggests that the data is a string or possibly a date.
Allan
Thanks alot allan,
have created a jsfiddle:
https://jsfiddle.net/LmraxL5q/2
For some reason the add row function is not functioning on there so i created one with a second row:
https://jsfiddle.net/Ld9sqrad/3
In the function
date-uk-pre
thea
parameter is0
when activating the sort on column index 1. Thus the error.That in turn is coming from
$.fn.dataTable.ext.order['dom-text-numeric']
. I think you'd probably need to update your code to reflect that that column is a date string rather than a number.Allan
ah Allan cant thank you enough!
that's the badger :)
Allan,
One last quick question.
Basically i have added the select row delete feature, it works great but in order for my calcs to function correctly, i've had to create a function that replaces id's in the cells above the row deleted.
The problem is that since i'm using
document.getElementById('pla'+(a + 1)+'').id = pla;
to change id's on each row, rows on the next page arn't in the DOM so only part my table is re-index.Is there a special way to make them visible on the DOM?
thanks
No - DataTables intentionally removes rows that aren't needed for the current display for performance and compatibility.
If you need to manipulate all of the rows int he table, use the DataTables API. Specifically look into
rows().every()
androw().node()
.Allan
Thanks again, i'm starting to see how it works now although it looks like i will format each array as a string, what will happen to values contained in the fields i'm editing will they be lost?
Just testing a few things out:
Using this as a test function, the only thing is my changes dont seem to be appearing on the table?
Also trying to get the table length
fnGetData().
is coming up as an unsupported method.See the top FAQ :-).
I would suggest you use
data()
rather than the legacy API method. The current API is fully documented here.Allan
ok that was a head ache ha, i guess if i'm working on every row there is no need to know the length.
Have used:
Thou now its updating strange things are happening may revert back soon, thanks!
Try utilizing all the below aspects of DataTable functionality. I believe each of these will better help you solve your problem/s.
https://datatables.net/reference/api/row()
https://datatables.net/reference/api/cell()
https://datatables.net/reference/option/columns.render
https://datatables.net/reference/option/createdRow
https://datatables.net/reference/option/columns.createdCell
https://datatables.net/reference/option/rowCallback
Also, just a suggestion, but instead of editing/manipulating the data within the table, why not edit the original data array, then call
If you utilize all the functionalities I linked to, that is all you would have to do to update your table.
Aw yes, thanks very much. Getting a much better understanding of it all now.
Looks like i'm gunna have to do a massive re-code of my project ha
Wish me luck, if only i found data tables earlier :)
The best advice I can give you is to take a week, if you can, and just play with DataTables in a test bed. I was lucky enough to take 1.5-2 weeks, and I am still learning. Another would be to use array of objects not strings, when you start using colVis and colReorder your life will be made so much easier.