Problem with DataTables Column visibility

Problem with DataTables Column visibility

hkrishnahkrishna Posts: 3Questions: 1Answers: 0

Dear friends,

I implemented user search feature in my project using datatables grid and datatables buttons.
When i click on a button, i need to show the list of users into the grid.

But i got this error "TypeError: this.s.subButtons[(1 * a[0])] is undefined"

My datatable initialization is
$('#dataTables-example').DataTable( {
dom: 'Bfrtip',
buttons: [
{
extend: 'colvis',
postfixButtons: [ 'colvisRestore' ]
}
],
columnDefs: [
{
targets: [-3,-4,-5,-8,-10],
visible: false
}
]
} );

But i didn't get any error when i use the datatable without databuttons like below :

$('#dataTables-example').DataTable({
"order": [[ 0, "desc" ]],
"aoColumnDefs": [ { "bSortable": false, "aTargets": [-1] }]});

I included all the required js and css files correctly....

Please help me ASAP.

Thanks & Regards
Hari

Answers

  • tarunsunejatarunsuneja Posts: 6Questions: 1Answers: 0

    I am also getting this error. Any help please?

  • allanallan Posts: 63,234Questions: 1Answers: 10,417 Site admin

    Hi,

    Could either of you link to a test case showing the issue so I can debug it please.

    Allan

  • hkrishnahkrishna Posts: 3Questions: 1Answers: 0
    edited August 2015

    Hi allen

    Thanks in advance.
    Please check please 2 url's
    1) http://iprogrammerindia.in/test/search-rides1.php
    2) http://iprogrammerindia.in/test/search-rides2.php

    First url display records with column visibility, second url just displays records.

    I called SearchRides('Today'); function for each 5 seconds of interval.

    I used below code for search-rides1.php , On first page load it works fine. After 5 seconds, SearchRides('Today') will call again. then i am getting the error that i explained in my previous post. And also Column visibility button disappeared after i again called to that function.
    $('#dataTables-example').dataTable( {
    dom: 'Bfrtip',
    buttons: [
    {
    extend: 'colvis',
    postfixButtons: [ 'colvisRestore' ]
    }
    ],
    columnDefs: [
    {
    targets: [-3,-4,-5,-8,-10],
    visible: false
    }
    ]
    } );

    I used below code for search-rides2.php . Here i am not at all getting the error that i explained above. It just works fine. But in above example i used column visibility.

    $('#dataTables-example').dataTable({
    "order": [[ 0, "desc" ]],
    "aoColumnDefs": [ { "bSortable": false, "aTargets": [-1] }]});

    Hope you understand. I am waiting for your reply. I will provide more info if necessary.

    Thanks
    Hari

  • allanallan Posts: 63,234Questions: 1Answers: 10,417 Site admin

    Hi,

    Super - thanks very much for the test case. There was an issue with Buttons whereby the buttons in a collection weren't being destroyed correctly. That caused the event listeners to remain and thus the error you are seeing.

    I've now committed the fix and the nightly version of Buttons is up to date with this change. It will be included in the 1.0.2 release of Buttons.

    Thanks for your help in tracking it down.

    Allan

  • hkrishnahkrishna Posts: 3Questions: 1Answers: 0

    OK allan.

    And one more thing.
    Once check this image : http://s11.postimg.org/lpwyr9sg3/Capture.png
    I have a scenario, I will select column visibility fields by selecting them. Whenever i refresh the page, again default columns are visible.
    How do get the selected column numbers on selected. So that i wll store them in session or other, and once page refresh i will use those number to show in the grid..

    Hope you understand....

This discussion has been closed.