Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

352
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda