How to iterate over rows with a specified sort order.

How to iterate over rows with a specified sort order.

CraigJCraigJ Posts: 30Questions: 12Answers: 2

I have a datatable that has reorder rows enabled. See here: https://c9pets.erpecommerce.com/express/

For example add items TOYRED, TOYBLUE and CRATEWIRE. You can drag the rows and they reorder. When a quantity is edited or a row is added I iterate over the rows and save info in local storage using rows.every(). (I haven't yet added the save to the row reorder event).

This works but the rows are stored in the original order - this can be seen using Chrome developer tools -> Resources -> Local Storage. I need them to be stored using the current order. I have tried .rows({search:'applied', order:'applied'}).every() but this doesn't have any effect on the order in which every iterates over the rows. THe Javascript that stores the data is in c9.express.js on line 292.

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 61,726Questions: 1Answers: 10,109 Site admin
    Answer ✓

    You'd need to use a different iterator at the moment - .rows({search:'applied', order:'applied'}).indexes().each( ... ) for example. It isn't quite as convenient as the every iterator, but that looks like it is currently using the index order (which I'm surprised about - I need to look into that).

    Allan

  • CraigJCraigJ Posts: 30Questions: 12Answers: 2
    edited March 2016

    This is what I ended up with:

    c9.express.dataTable.rows({search:'applied', order:'applied'}).eq(0).each( function(index){

    Thanks.

This discussion has been closed.