datatable hide column, initial sort and sort first column using values from second column

datatable hide column, initial sort and sort first column using values from second column

niedwiedzichoniedwiedzicho Posts: 3Questions: 1Answers: 0

HI!

I have table with 7 columns

<th><h5>Doc</h5></th>
<th><h5>No</h5></th>
<th><h5>Customer</h5></th>
<th><h5>Date</h5></th>
<th><h5>Due ate</h5></th>
<th><h5>Status</h5></th>
<th><h5>Options</h5></th>

my DataTable init is:

$(".data-table-class").DataTable( {
        "language": {
            "lengthMenu": "_MENU_ ",
            "zeroRecords": "no data",
            "info": "pg. _PAGE_ of _PAGES_",
            "infoEmpty": "no data",
            "loadingRecords": "loading...",
            "search":         "search:",
            "paginate": {
                "first":      "|<",
                "last":       ">|",
                "next":       ">",
                "previous":   "<"
            },
            "aria": {
                "sortAscending":  ": asc",
                "sortDescending": ": desc"
            },
            "order": [[ 1, "desc" ]],
            "columnDefs": [
                {
                    "targets": [0],
                    "visible": true,
                    "orderable": false,
                    "searchable": false
                },
                {
                    "targets": [1],
                    "visible": false,
                    "searchable": false
                }],
            "stateSave": true
        }
    } );

I want to:

  1. order by data from second column [No] on load
  2. hide second column [No]
  3. allow sort first column [Doc] using values from second column [No]
  4. remove sorting from columns: Doc, Options

I've tried to manipulate witg columns and columnDefs byt with no success - hiding, removing sorting and initial sort don't work
what am I doing wrong?

any help?

my current version: cdn.datatables.net/1.10.20

THANK YOU!

This question has an accepted answers - jump to answer

Answers

  • kthorngrenkthorngren Posts: 21,167Questions: 26Answers: 4,921
    edited March 2020 Answer ✓

    Looks like you have all the Datataubles options within the language option. Move the order, columnDefs and stateSave outside the language option, ie, after the } in line 33.

    Kevin

  • niedwiedzichoniedwiedzicho Posts: 3Questions: 1Answers: 0

    yap - this works!

    but how to sort first column usig data from hidden [second] column?

  • niedwiedzichoniedwiedzicho Posts: 3Questions: 1Answers: 0

    I've solved that
    thanks for help

This discussion has been closed.