Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

353
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda