Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

351
Views
rows().every function not working in jquery binded datatable

Hi I am using jquery datatable in my MVC page so .In 1 page I have to send all the data from the datatable to the controller. So what I did is I made all the datas into 1 array and I passed it to the controller. using code

 var AllSelectedData = [];
var selected = [];
    table = $('#Distpopup').DataTable();
    table.rows().every(function () {
        var d = this.data();
        AllSelectedData.push(d);
    });
    $("#dtlist").val(AllSelectedData);

It is working fine for model binded datatable but in 1 case I am having a datatable which is binded using ajax in that case it is not working.Any suggestions

about 4 years ago · Santiago Trujillo
2 answers
Answer question

0

You can access all the rows of the table in model binding and also in Ajax.

e.g. this is your datatable initialization.

var table = $('#Distpopup').DataTable();

After adding data to the table you want to get this data in an array. If you want to send data to the controller use JSON.stringify() to stringfy your data and then send it to the controller and you can use it in model binding with a form field or also you can pass this stringfy data using Ajax request.

var AllSelectedData = [];
table.rows().every(function () {
     var d = this.data();
     AllSelectedData.push(d);
});

$("#dtlist").val(JSON.stringify(AllSelectedData));

I also face this issue see this question that it still has no answer.

about 4 years ago · Santiago Trujillo Report

0

You can use datatable callbacks, http://legacy.datatables.net/usage/callbacks

One way to do it using initcomplete callback function which works when the table has been initialised.

$('#Distpopup').DataTable({
          //Other settings
         "fnInitComplete": function (oSettings, json) {
               console.log(json.data);
            },
});

Another way using createdrow function which works every row created

var AllSelectedData = [];
    $('#Distpopup').DataTable({
              //Other settings
            "createdRow": function (row, data, index) {
                  AllSelectedData.push(data);
                },
    });
about 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!