Configuration of DataTable in PUG (Jade)

Configuration of DataTable in PUG (Jade)

RaginRagin Posts: 6Questions: 1Answers: 0

Hi,
I am using the dataTables by specifiying them in a Jade-Template this way:

        .table-responsive.mt-2
          data-table(:rows="orderItems", :sort-by-column="2", :filtering="false")

Now I need to allow ordering only for column 2.

I know this should be done using orderable and target, but I really cannot get i working..

Anyone there who can show me the correct way?

Ragin

Answers

  • RaginRagin Posts: 6Questions: 1Answers: 0

    data-table(:rows="orderItems", :sort-by-column="2", :columnDefs: "[targets: [1,2], orderable: false }]"

    this crashes my complete template...

  • kthorngrenkthorngren Posts: 21,343Questions: 26Answers: 4,954

    Don't know anything about PUG but it looks like you are missing a { between [ and targets to open the object definition. Maybe you are missing the closing ). Something like this maybe:

    data-table(:rows="orderItems", :sort-by-column="2", :columnDefs: "[{targets: [1,2], orderable: false }]")

    Kevin

  • RaginRagin Posts: 6Questions: 1Answers: 0

    Hi Kevin,
    you were right. I corrected this but still all my columns are orderable.

  • RaginRagin Posts: 6Questions: 1Answers: 0
    edited December 2019

    :ordering= "true", :columns= "[{orderable: true} , {orderable: true} , null, null, null, null, null, null }]",

    tried this. but then also the jade precompiler crashes...

  • RaginRagin Posts: 6Questions: 1Answers: 0

    solved it now using javascript to re-initialize that table...

  • RaginRagin Posts: 6Questions: 1Answers: 0
    edited December 2019
      script(type="text/javascript").
        $(document).ready(function () {
          if ($.fn.dataTable.isDataTable('#tableOrderGeneric')) {
            $('#tableOrderGeneric').DataTable({
              destroy: true,
              'columnDefs': [{
                'targets': [2,3,4,5,6], /* column index */
                'orderable': false, /* true or false */
              }],
              ordering: true,
              searching: false,
              paging: false
            });
          }
          console.log('table re-initialized')
        });
    

    that works now...

    Edited by Colin - Syntax highlighting. Details on how to highlight code using markdown can be found in this guide.

This discussion has been closed.