Multi-row editing is not working.

Multi-row editing is not working.

kartikeyas00kartikeyas00 Posts: 16Questions: 4Answers: 0

I am working on python flask web application where I am having a problem with the multi-row editing, The problem is very basic ie: When I select multiple rows and they have different values, I can't see any message in the fields like 'Multiple Values'. I only see the value of the last row in the field. When I try to put a value there as I want the same value for all the rows in the column, it only updates the value of the row above the last one. Test case is below. You can press the Add Row button several times to test the multi-row editing bug. Thanks a ton!

Link to test case:
http://live.datatables.net/bewuniwu/1/edit

Debugger code (debug.datatables.net/ewoyus):

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin

    I don't see an add row button I'm afraid?

    Allan

  • kartikeyas00kartikeyas00 Posts: 16Questions: 4Answers: 0
    edited August 2020

    Hi @allan , if you clone it and look at the full preview, you will find the add row button!

  • kartikeyas00kartikeyas00 Posts: 16Questions: 4Answers: 0

    @allan Also, you have to look at the Live Preview. For some reason the data table buttons are not showing up in the small preview screen!

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    Answer ✓

    How odd! It appears the JSBin runner will throw a syntax error when using a back tick template string! It is only used once in your JS - for the alert warning. Comment that out and it works.

    Took me a little while to realise what was going on there, but it is due to how the rows are being added by that Create row button:

              var data = table.row(":last", { order: "applied" }).data();
              if (typeof data === "undefined") {
                data = {};
                data["id"] = 1000;
                data["extension_1"] = "";
                data["extension_2"] = ""; 
                //  ...
              } else {
                data["id"] = data["id"] + 1;
                data["total_pieces"] = table.data().count() + 1;
              }
    

    What is happening is that the table.row(...).data() method gets the original data object that was added to the table. So the if condition is modifying that object (i.e. the original), not a new copy.

    So you need to make a new copy in the else:

                data = $.extend({}, data);
    

    Otherwise the data all appears the same since the same object is being used for multiple rows! Updated example here http://live.datatables.net/nagokano/1/edit .

    Allan

  • kartikeyas00kartikeyas00 Posts: 16Questions: 4Answers: 0

    Awesome! Cheers Allan!

This discussion has been closed.