Can I use DataTables colReorder functions with jasmine unit test?
Can I use DataTables colReorder functions with jasmine unit test?
och_datatables
Posts: 3Questions: 1Answers: 0
I am trying to create a jasmine unit test on my DataTable to test stuff when columns are ordered with the colReorder plugin.
However, when I'm running the test, I'm getting an error msg from the colReorder library. This is my test code.
describe('Reorder', function(){
it('It works', function () {
var table = $('#myTable').DataTable().colReorder;
//Get order
var ordering = table.order();
});
});
The error occurs on line 1337 in file dataTables.colReorder.js
if ( $.fn.dataTable.Api ) {
$.fn.dataTable.Api.register( 'colReorder.reset()', function () {
return this.iterator( 'table', function ( ctx ) {
ctx._colReorder.fnReset();
} );
} );
The _colReorder variable is null, and hence the fnReset method is failing.
Anybody have any tips on how to get this to work?
This discussion has been closed.
Answers
That suggests that your table doesn't have ColReorder enabled on it. Have you used the
colReorder
option to enable it (I don't see it in the above code).Allan
Ok, I'll check if that will work.
Hi again.
Tried to add colReorder to my table with this function
Now the order(); function works to output current column ordering
However, when I try to alter the order, something fails:
The error message follows is this:
TypeError: Cannot read property 'aoColumns' of null
at n.fn.dataTableExt.oApi.fnColReorder
Is there still error in the way colReorder has been initiated?
Assuming
myTable
is the result from$().DataTable()
then it should work okay. I'd really need a test case to be able to determine what is going wrong.Allan