Editor Edit all selected rows and submit

Editor Edit all selected rows and submit

jmccolgan93jmccolgan93 Posts: 13Questions: 8Answers: 0

hey,

I built a custom button to get all the selected rows and change the value of a column based on another. it works great but I can't get it to submit multiple lines I have multiple selected.

is there a better way to do this or am I just missing something here.

{
        text: "Return",
        editor: editor,
        className: "mb-2 btn btn-small btn-primary",
        enabled: false,
        action: function (e, dt, node, config) {
          let rows = dt_fixedheader.rows(".selected");
          console.log("# of selected=" + rows.data().length); //it shows number of selected row
          if (rows.data().length > 0) {
            rows.every(function (rowIdx, tableLoop, rowLoop) {
              console.log(rowIdx, tableLoop, rowLoop)
              editor.edit(dt_fixedheader.row(rowIdx), false).set("checkedin", editor.get("checkedout")).submit();
          
            });
          }
        },
      }

Answers

  • allanallan Posts: 61,972Questions: 1Answers: 10,160 Site admin

    You need to use the multi-row editing API to do what you are looking for.

    Rather than calling edit() on each row, pass all the rows to a single edit() call, and then using the multi-row editing API to adjust the values as needed. Then you can submit the whole lot together.

    There are a couple of issues doing it as one edit call per row:

    1. You need to wait for the previous edit to complete its submission. This is:
      • Slow!
      • Complex (you need a queuing mechanism)
    2. You are providing an easy way for someone to DDoS your own server! Say you have 50k rows and select them all - then submit - that's 50k Ajax requests the server needs to handle.

    Multi-row editing is the way to go :)

    Allan

Sign In or Register to comment.