Can I use DataTables colReorder functions with jasmine unit test?

Can I use DataTables colReorder functions with jasmine unit test?

och_datatablesoch_datatables Posts: 3Questions: 1Answers: 0
edited April 2016 in Free community support

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?

Answers

  • allanallan Posts: 61,880Questions: 1Answers: 10,139 Site admin

    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

  • och_datatablesoch_datatables Posts: 3Questions: 1Answers: 0

    Ok, I'll check if that will work.

  • och_datatablesoch_datatables Posts: 3Questions: 1Answers: 0

    Hi again.
    Tried to add colReorder to my table with this function

                new $.fn.dataTable.ColReorder(myTable, {
                       options
                });
    

    Now the order(); function works to output current column ordering

    var order = myTable.colReorder.order();
    
    

    However, when I try to alter the order, something fails:

    //Switches column 4 and 5
    myTable.colReorder.order([0,1,2,3,5,4]);
    
    

    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?

  • allanallan Posts: 61,880Questions: 1Answers: 10,139 Site admin

    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

This discussion has been closed.