This topic is locked

Set child details row number to keep things in order

11/6/2013 12:55:53 PM
PHPRunner Tips and Tricks
F
FunkDaddy author

Here's a handy tip... let's say you are creating a shopping cart or invoice app. You want users to be able to add things to their order via inline add using master/child setup. So, you have an invoice as a Master and invoice details as the line items that will be part of that invoice.
When you enter each invoice item using inline add in the child table and hit "save all" to record all the items, PHPR may not necessarily save them in the order that you entered those items. So if enter item A, B, C, D, E, etc... after saving all, the child list page may actually show something like A,C,D,E,B, etc... or simply in reverse order E,D,C,B,A because PHPR attempts to save things from "top to bottom"... so whatever you entered first is actually shown all the way at the bottom and saved last during a save all operation.
Yes, you can sort before SQL on the child table to give you the order you want, but other factors can come into play which may not give you the clean sorting you were hoping for (showing the exact order in which you entered your items).
So, here's what you can do:
In add page "Javascript OnLoad Event" you can simply make use of "pageObj.inlineAdd.rows.length" and it returns the current row number of the items you pressed the "inline add" button. To see this in action simply add "console.log(pageObj.inlineAdd.rows.length);" to any of your inline add pages of a child type records page and you'll see it return the correct row number for that given subset of child records.
From there, you can now use that value to track in what order things are entered in your child records :-)