When I set a default column for ordering and direction, all other Datatable options are disabled

When I set a default column for ordering and direction, all other Datatable options are disabled

R_GR_G Posts: 31Questions: 10Answers: 0

I have the following initialization code:

$(document).ready(function () {
    // General DataTable with no special actions
    var datatable = $('#datatable').DataTable({
        responsive: true,
        autoWidth: false,
        pagingType: 'full',
        jQueryUI: false
    });
    // Logs DataTable with sort on updated_at
    var logstable = $('#logstable').DataTable({
        responsive: true,
        autoWidth: false,
        pagingType: 'full',
        jQueryUI: false,
        order: [[7, "desc"]]
    });
   ...

If I use id="datatable", all is normal. If I use id="logstable", I get the ordering that I request. However, all other options disappear. I no longer have the capability to order columns, page, search, etc. Also, the table is no longer responsive which is my primary issue in this particular case. Is this expected? What can I do to select a default column and order and yet still maintain all the other options, especially a responsive table? Thanks so much for your code and your support!

Answers

  • R_GR_G Posts: 31Questions: 10Answers: 0

    I should note that I am using gem 'jquery-datatables-rails', '3.2.0' under Rails 4.0.3. That gem wraps DataTable 1.10.

  • allanallan Posts: 61,822Questions: 1Answers: 10,129 Site admin

    Can you link to the page in quesiton so I can debug it please.

    Allan

  • R_GR_G Posts: 31Questions: 10Answers: 0

    http://ucf.kctdb.com I will email you login information since this is public.

    Login using logon information I just sent.

    Select All Cars. Note the options that are enabled as they should be with the log table. (Not sure what happened to my clear icon, but that's a different issue...)

    Click on the first car, FCE1049A, or really any of them...

    The table at the bottom shows the last five log entries in descending order. It currently is sorted by the last column and so all the datatable options are gone. If I remove the order option, it looks like the All Cars table.

  • allanallan Posts: 61,822Questions: 1Answers: 10,129 Site admin

    Thanks for the link - got it now.

    order:[[7,"desc"]]

    But there are only 7 columns in the table... (keep in mind that arrays in Javascript are 0 based).

    That at least appears to be the error, although it is difficult to be sure with the compressed code.

    Allan

  • R_GR_G Posts: 31Questions: 10Answers: 0

    That fixed it. I meant to double check that question when I entered 7 but got busy and didn't. Thanks again for your help.

This discussion has been closed.