Edit multiple rows in a loop

Edit multiple rows in a loop

marialpettitmarialpettit Posts: 7Questions: 3Answers: 0

DataTables Debugger: onipad

I'm trying to "clone" selections from one row to multiple others.

Javascript code:

var iConfirm = window.confirm("Are you sure you want to clone build selections from " + deviceSource + " to " + deviceTargets + "?");
                    
                    if (iConfirm)
                    {
                        var sourceData = dtSurveyBuild.row(sourceIndex).data();
                        var sFacility = sourceData["NEW_DEVICE_FACILITY_CODE"];
                        var sDomain = sourceData["NEW_DEVICE_DNS_DOMAIN"];
                        var sOS = sourceData["NEW_XD_OS"];
                        var sWT = sourceData["NEW_XD_TYPE"];
                        var sTemplate = sourceData["NEW_XD_CUSTOM_TEMPLATE"];
                        var sOptions = sourceData["APP_OPTIONS"];                        
                        
                        while (iList.length > 0) {
                            var rowIndex = iList.pop();
                            var row = dtSurveyBuild.row(rowIndex);

                            eSurveyBuild
                                .edit(row, false)
                                .set('NEW_DEVICE_FACILITY_CODE', sFacility)
                                .set('NEW_DEVICE_DNS_DOMAIN', sDomain)
                                .set('NEW_XD_OS', sOS)
                                .set('NEW_XD_TYPE', sWT)
                                .set('NEW_XD_CUSTOM_TEMPLATE', sTemplate)
                                .set('APP_OPTIONS', sOptions)
                                .submit();

                        }

I have stepped through the code... the while statement iterates as expected and the JSON result comes back with no errors. However, the DataTables Editor will only update the first item. All other items seem to be ignored.

Any tips would be appreciated.

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 63,689Questions: 1Answers: 10,500 Site admin
    Answer ✓

    Hi,

    What you would need to do at the moment is wait until the submit completes before you then progress on to edit the next row (submitComplete would let you know).

    The reason for this is that Editor is a single row editor only at the moment - and since the Ajax call is asynchronous you are effectively trying to edit multiple rows while there are already one or more rows being updated.

    Editor 1.5 which will be available in the next few weeks will introduce multi-row editing.

    Regards,
    Allan

  • marialpettitmarialpettit Posts: 7Questions: 3Answers: 0

    Got it working with that tip. Thank you!

    eSurveyBuild.on('submitComplete', function (e, json, data) {
    
                processEditQueue();
    
            });
    
            function processEditQueue()
            {
                if (editQueue.length > 0) {
    
                    var item = editQueue.pop();
                    var sourceIndex = item.source;
                    var rowIndex = item.target;
                    var row = dtSurveyBuild.row(rowIndex);                
                    var sourceData = dtSurveyBuild.row(sourceIndex).data();
                    var sOldDevice = row.data()['OLD_DEVICE_NAME'];
                    var sFacility = sourceData["NEW_DEVICE_FACILITY_CODE"];
                    var sDomain = sourceData["NEW_DEVICE_DNS_DOMAIN"];
                    var sOS = sourceData["NEW_XD_OS"];
                    var sWT = sourceData["NEW_XD_TYPE"];
                    var sTemplate = sourceData["NEW_XD_CUSTOM_TEMPLATE"];
                    var sOptions = sourceData["APP_OPTIONS"];
    
                    eSurveyBuild
                        .edit(row, false)
                        .set('NEW_DEVICE_FACILITY_CODE', sFacility)
                        .set('NEW_DEVICE_DNS_DOMAIN', sDomain)
                        .set('NEW_XD_OS', sOS)
                        .set('NEW_XD_TYPE', sWT)
                        .set('NEW_XD_CUSTOM_TEMPLATE', sTemplate)
                        .set('APP_OPTIONS', sOptions)
                        .submit();
    
                }
            }
    
            var editQueue = [];
    
    
  • allanallan Posts: 63,689Questions: 1Answers: 10,500 Site admin

    Good to hear! Thanks for posting your solution code for us.

    Allan

This discussion has been closed.