error for updating a row holds chackbox in JQuery DataTable

error for updating a row holds chackbox in JQuery DataTable

elenoraelenora Posts: 23Questions: 10Answers: 0
edited February 2021 in Free community support

Hi. I'm implementing asp.net core 3.1. I have JQuery DataTable and I implemented it in serverside mode. it has a few columns and the firs column holds checkboxes. After user selects some checkboxes and clicks on a button, the ids of them via ajax request goes to the related method and their status get changed and then the updated ones got back to the ajax to update the related rows. Here below is what I have tried till now:

$('#grantAccess').click(function () {

              
                var OTable = $("#myDummyTable").dataTable();

                $("input[type=checkbox]:checked", OTable.fnGetNodes()).each(function () {


                    var row = $(this).closest('tr');

                   
                 //table row object
                   var newRow = oTable.row(row);

                    keepSelectedRows.push(newRow);
               
                    selectedIds.push($(this).closest("tr").find("td:eq(1)").text());

                    var Id = $(this).closest("tr").find("td:eq(1)").text();
                   
                    var ApplicantName = $(this).closest("tr").find("td:eq(3)").text();
              
                    var LogDate = $(this).closest("tr").find("td:eq(6)").text();


                });

                                    

                $("input[name='hiddeninput']").val(selectedIds);

                    $('#showDataModal').modal('show');

            });

    


    jQuery(document).ready(function ($) {

    $("#deletethem").click(function () {
            var OTable = $("#myDummyTable").DataTable();
        
    $.ajax({
        url: "Requestes/Operation",
        type: "POST",
        async: true,
        cache: false,                
        data: { "Id": selectedIds},
        success: function (data) {

            $.each(data, function (index, value) {
//for updating the related row              
                OTable.row(keepSelectedRows.pop()).data(data).draw(false);

            })
        }
    });
  });
});

//The controller method
 public  IList<JsonTO>  Operation(List<int> Id){

List<JsonTO> data = new List<JsonTO>();

foreach (var index in query)
                {
                    aJson = new JsonTO();
                    aJson.id = index.id;
              
                    aJson.applicantName = index.applicantName;
                
                    aJson.logDate = index.logDate;
              
                    data.Add(aJson);
                }

return data

}

Now my problem is, for updating the selected row, the firs column of the selected row has a checkbox while the returning data from the controller method has not the checkbox as its firs column so it shows me an error DataTables warning: table id=myDummyTable - Requested unknown parameter '' for row 8, column 2. For more information about this error, please see http://datatables.net/tn/4

I appreciate if anyone helps me.

Edited by Colin - Syntax highlighting. Details on how to highlight code using markdown can be found in this guide.

Answers

  • allanallan Posts: 63,523Questions: 1Answers: 10,473 Site admin

    var OTable = $("#myDummyTable").DataTable(); - is that your DataTables initialisation, or have you got it building somewhere else? Could you either give me a link to your page, or use the debugger to give me a trace please - click the Upload button and then let me know what the debug code is. Also, can you show me the JSON response from the server from your Operation controller.

    Thanks,
    Allan

This discussion has been closed.