0

I have a table which contains more than 1000 rows and I used JQuery Datatable for pagination and searching. Everything is working fine but when the user wants to update anyone column value, each row one by one need to update. This is taking much time for 1000 rows.

My Question: Is there any possibilities like bulk edit. Example if I select which row I want to update like I will select 100 rows then I will update the only one-row value and when I click update automatically all 100 rows has to update.

SENA
  • 119
  • 1
  • 2
  • 16

1 Answers1

1

In general terms, you can do something similar to this:

  1. Use select plugin for checkboxes in datatables for user selection (muti option). You cant add selectAll and selectNone buttons like this.

  2. Create a js function where you get all the selected id of rows with this sample code:

    var idsSelected = myTable.rows({ selected: true }).ids().toArray();
    

    (this requires ajax and rowId in constructor like this).

  3. Create a form inside modal, for example, with the new data and fields, for example, fieldX and fieldY.

  4. When user click in send button, make an ajax call and send rows ids and form data to a controller.

    For example:

     $.ajax({
         url: miUrl,
         method: miMEthod,
         traditional: true,                                 //  We need this for send array of integers
         data: {
             Ids: myTable.rows({ selected: true }).ids().toArray(),
             ParamX: $("#paramX").val(),
             ParamY: $("#paramY").val()
         },
         success: function (response) {    
              $("#response").html("COMPLETE !!!");
         },
         async: true
     });
    

    In .net, if you want to send an array of integers to a controller, make sure you have traditional: true in ajax, otherwise, it can give problems

    Controller will be something similar to this:

     [HttpPost]
     public ActionResult MyMethod(int[] Ids, string ParamX, string ParamY)
     { ... }
    
  5. Make an update in database with the data in point 4.

Dani
  • 1,825
  • 2
  • 15
  • 29