is there a method to reset datatable ?

is there a method to reset datatable ?

copsychuscopsychus Posts: 20Questions: 5Answers: 0

even i refresh a page, table still remember all the things i did in previous, like all checkbox still checked , pagination still the same page not first page, is there a option to fix this ? i want fresh start everytimes it reload
.
Another question, is there any methods to checked checkbox only in current pagination? when i press checked all, all checkbox including other pages also checked, i don't want this and is it possible to checked only current pagination and when u moving to next page, you won't see the checkbox being checked anymore?

This question has an accepted answers - jump to answer

Answers

  • rf1234rf1234 Posts: 2,947Questions: 87Answers: 416
    edited May 2020

    even i refresh a page, table still remember all the things i did in previous, like all checkbox still checked , pagination still the same page not first page, is there a option to fix this ? i want fresh start everytimes it reload

    Not here. I only have this when I use state saving. Are you using state saving? If so don't use it. If you are not using it and can't fix it please post a test case as per the forum rules.
    https://datatables.net/reference/option/stateSave

    Another question, is there any methods to checked checkbox only in current pagination? when i press checked all, all checkbox including other pages also checked,

    You can use "rows()" with "page: current" like in here:
    https://datatables.net/reference/api/rows()
    https://datatables.net/reference/type/selector-modifier

    if ( dt.rows( ':not(.parent)', { page: 'current' } ).count() > 
         dt.rows( '.parent',       { page: 'current' } ).count()    ) {
       .... do something
    

    and is it possible to checked only current pagination and when u moving to next page, you won't see the checkbox being checked anymore?

    You can use the "page" event and make sure everything is unchecked when the user pages through the data.
    https://datatables.net/reference/event/page

  • copsychuscopsychus Posts: 20Questions: 5Answers: 0

    for First question: after i check the code, there is "bstatesave" in my code, so i removed it and work like perfectly fine, i realy appreciate this, thank you :D
    .
    for Second question, i still have no ideal how to control checkbox in current page

    if ( dt.rows( ':not(.parent)', { page: 'current' } ).count() >
         dt.rows( '.parent',       { page: 'current' } ).count()    ) {
    // what to do here?
       .... do something
    

    i use checkbox from here :

    columnDefs: [
                         {
                             width: "8%",
                             orderable: true,
                             targets: 0,
                             checkboxes: { selectRow: false, }
    
                         }
                     ],
    

    for Last question, i tried call with this but seem like nothing work:

     $('#tbGrid').on('page.dt', function () {
                     table.$('input').removeAttr('checked');
                 });
    
  • copsychuscopsychus Posts: 20Questions: 5Answers: 0

    For last question , i found solution, everything work fine , so only second question left

    $('#tbGrid').on('page.dt', function () {
                     table.columns().checkboxes.deselect(true);
                 });
    
  • copsychuscopsychus Posts: 20Questions: 5Answers: 0

    oh, just got new piece of knowledge from last answer , so second question solved now, thank you :D , i'm using this

    $('#tbGrid input[type="checkbox"]').click(function () {
    
                     if (table.rows(':not(.parent)', { page: 'current' }).count() >
                         table.rows('.parent', { page: 'current' }).count()) {
    
                         table.columns({ page: 'current' }).checkboxes.select(true);
                     }
                 });
    
  • rf1234rf1234 Posts: 2,947Questions: 87Answers: 416
    Answer ✓

    Glad you got it working!! but the code I posted on this was just to show the syntax. It is not relevant for your use case. Probably better to use just this in case that works for you.

    $('#tbGrid input[type="checkbox"]').click(function () {
      table.columns({ page: 'current' }).checkboxes.select(true);
    });
    
  • copsychuscopsychus Posts: 20Questions: 5Answers: 0

    Thanks :D working like a charm

This discussion has been closed.