Batch updating with Editor

Batch updating with Editor

johnblythejohnblythe Posts: 92Questions: 21Answers: 2

Hi there,

First off, thanks a bunch for the great suite.

We're allowing users to modify their sales offer to other users with a blanket discount to the entire order. As such, we'd like to reflect that in the table's price column. I can't seem to find any information on a batch update of sorts. Right now we have to loop through each row and run our update script. This isn't the fastest by any means and will certainly be a bad UX for larger orders (it takes several seconds for an order of only 18 items, some orders will have hundreds or even thousands).

Here's our code for reference:

$(document).on('click', '.apply-discount', function() {
        for (i in dtCollection[id].rows()[0]) {
            var rowIndex = dtCollection['fancybox-line-items-0'].rows()[0][i];
            var row = dtCollection['fancybox-line-items-0'].row(rowIndex);

            for (j in dtfields) {
                if (dtfields[j].data == 'offerPriceUom') {
                    var cellIndex = j;
                    break;
                }
            }

            var price = row.cell(rowIndex, j).data();
            price -= round( price * ( parseFloat($(trig).parent().find('input').val()) / 100 ), 2 );

            editQueue.push({row: row, price: price });
        }

        // process our queue of edits
        processEditQueue();
    });

and the edit queue function:

function processEditQueue()
    {
        if ($.active <= 0) {
            var item = editQueue.pop();
            if (item) {
                editor
                    .edit( item.row, false )
                    .set( 'offerPriceUom', item.price )
                    .submit(processEditQueue);
            }
        } else {
            setTimeout(processEditQueue, 100);
        }
    }

Have I overlooked pieces of the reference/manual or discussions within the forum?

Thanks for any pointers!

This question has an accepted answers - jump to answer

Answers

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

    Hi,

    Currently Editor doesn't support batch row updates - that is something that will be coming in v1.5!

    At the moment your workaround is probably the best way of doing it (if not ideal - until the core supports it :-) ).

    Allan

  • johnblythejohnblythe Posts: 92Questions: 21Answers: 2

    :'(

    Was hoping I was wrong and had overlooked a means of doing it. Oh well, we'll just have to wait for 1.5!

    In the mean time I think we're going to do something similar to above, but without the actual edit itself. Rather, simply update the data() in the DataTable per row, save the applied discount amount via a separate (and single) ajax request and then render accordingly on the next load as opposed to running our Editor's save function for each and every item.

    Thanks for the quick reply!

    Oh, one other question out of curiosity: any sense of ETA for 1.5?

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

    Not too long away :-). I expect the release cycle for 1.5 to be much faster than 1.4 was. However, there are other components which need to be updated before multi-row editing in Editor will be feasible, so it will likely still be a few months away.

    I'm very keen to get it going though - I think its going to be a great little feature :-).

    Allan

  • johnblythejohnblythe Posts: 92Questions: 21Answers: 2

    Awesome. That'll be huge for enterprise-y projects like ours.

    Keep up the good work and thanks again!

This discussion has been closed.