dimanche 2 juillet 2017

How can i prevent data lost from previous pagination link after navigate to another page

I am using laravel lengthawarepaginator. I have a checkboxes with it. I am using div to display data as grid view. When i click a button to select all the check boxes it only check for the first page, and when navigate to another pages then the data from previous page will lost.

This method below is used to refresh the data when navigate to new page.

 $( document ).ready(function() {
        $('.pagination a').on('click', function(event) {
          event.preventDefault();
            if ($(this).attr('href') != '#') {
                $('#list').load($(this).attr('href'));
            }
        });
    });

    $(document).ready(function (){
   var table = $('#example').DataTable({
      ........
   });

   // Handle click on "Select all" control
   $('#example-select-all').on('click', function(){
      // Get all rows with search applied
      var rows = table.rows({ 'search': 'applied' }).nodes();
      // Check/uncheck checkboxes for all rows in the table
      $('input[type="checkbox"]', rows).prop('checked', this.checked);
   });

   // Handle click on checkbox to set state of "Select all" control
   $('#example tbody').on('change', 'input[type="checkbox"]', function(){
      // If checkbox is not checked
      if(!this.checked){
         var el = $('#example-select-all').get(0);
         // If "Select all" control is checked and has 'indeterminate' property
         if(el && el.checked && ('indeterminate' in el)){
            // Set visual state of "Select all" control
            // as 'indeterminate'
            el.indeterminate = true;
         }
      }
   });

   // Handle form submission event
   $('#frm-example').on('submit', function(e){
      var form = this;

      // Iterate over all checkboxes in the table
      table.$('input[type="checkbox"]').each(function(){
         // If checkbox doesn't exist in DOM
         if(!$.contains(document, this)){
            // If checkbox is checked
            if(this.checked){
               // Create a hidden element
               $(form).append(
                  $('<input>')
                     .attr('type', 'hidden')
                     .attr('name', this.name)
                     .val(this.value)
               );
            }
         }
      });
   });
});

I want to do something like this, but i am not using datatable to display data, is it possible to make it?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire