asp.net mvc - How to post data for the whole table using jQuery DataTables -


i have table working jquery datatables , pagination

i have on 300 registrys 50 max on each page. every time change page page other 250 registrys removed dom when submit , post controller list of 50 models ones on current page.

how access other 250, or tell table send them all? have searched , have read normal behavior of pagination. how guys work around it?

cause

when using datatables plug-in pagination current page rows exist in dom performance , compatibility. therefore when submit form, current page form controls values being submitted.

solution 1: submit form directly

the trick turn form elements pages other current <input type="hidden"> before submitting form.

var table = $('#example').datatable();  // handle form submission event $('#frm-example').on('submit', function(e){    var form = this;     // encode set of form elements pages array of names , values    var params = table.$('input,select,textarea').serializearray();     // iterate on form elements    $.each(params, function(){       // if element doesn't exist in dom       if(!$.contains(document, form[this.name])){          // create hidden element          $(form).append(             $('<input>')                .attr('type', 'hidden')                .attr('name', this.name)                .val(this.value)          );       }    }); }); 

see this example code , demonstration.

solution 2: submit form via ajax

another solution submit form via ajax.

var table = $('#example').datatable();  // handle form submission event $('#frm-example').on('submit', function(e){    // prevent actual form submission    e.preventdefault();     // serialize form data    var data = table.$('input,select,textarea').serialize();     // submit form data via ajax    $.ajax({       url: '/echo/jsonp/',       data: data,       success: function(data){          console.log('server response', data);       }    }); }); 

see this example code , demonstration.

notes

please note both solutions work in client-side processing mode only.

links

see jquery datatables: how submit pages form data more details.


Comments