auto sort without clicking on sort manually

This public forum is for user-to-user discussions of PHPMaker. Note that this is not support forum.
Post Reply
ceeronne
User
Posts: 22

auto sort without clicking on sort manually

Post by ceeronne »

Is there a way to set when I add record to data base that record goes to the end of all records no mather that i have set to be sorted as ascending by one of the comlimns, it should be displayed automaticly for an instance if I have set ti sort all to be ascending by column M2 which is all numbers ind its sorted ok but when I add new record it goes to the end of all records and i have to click on M2 thice to sort it again and then its sorted, coud i do something to put that record in its place automaticly without clicking on sort manualy


kirondedshem
User
Posts: 642

Post by kirondedshem »

  1. If your table has a field whose value always grows for every new record, for example if your primary key id field is an auto increment, OR you have a filed like entry_date(for my case its a timestamp for when a record was entered into the database, so i use row_inerting to assign ew_CurrentDateTime() to it and its not editable), you can set the sort property of the table settings to sort by that column ascending by default, so everytime you add a new record since it has a higher value of that field than any it will always go to the bottom.

If you set sort property in table settings the sorting will always apply automatically, you can even disable sort on field settings list section of other fields if you dont want users to manually change the sort order themselves.
So for your case If we assume M2 is a number column(am not sure what number are assigned and what algorithm is used here), ensure the value assigned to it is incremental in some way and as long as you set sort property in table settings to use field M2 ascending, the sorting will always be applied automatically.


ceeronne
User
Posts: 22

Post by ceeronne »

Thank You for reply.
MY M2 column is not auto incremental , it is column for square meters for certain flats so it is allways a number, I have of course ithe auto increment column which is ID and i assume that always puts a new record to and end by that auto increment No and everything is ok with that but if I have allready clicked on a M2 row to sort ewerything by its , but this is only thing that I would like to fix values why it puts a new record on the end when its set to ASC by M2 values


kirondedshem
User
Posts: 642

Post by kirondedshem »

What I understand is lets say that you want records to be ordered by M2 ascending, but then a user clicks on some other field to use during sorting like filed_5. You want everytime after adding a new record the table should go back to being sorted by M2 ascending such that it can show the record at the very bottom irrespective of what sort order was currently set on the list by user.

If so then you basically want to overirde the sort order everytime a new record is added for that table.Fortunaltely, in table settings there is aplace to set return page after add, by default this goes to the list page eg if your table is called flats, by default after add the site goes to "flatslist.php".

LOGIC:Php maker determines what column to sort by using get parameters. ie when a user clicks to sort by M2 wanting to sort by ascending, the url always looks like "flatslist.php?order=M2&ordertype=ASC".
Assuming you want after a record is added to reset sort order to M2 ascending
So all we have to do is order the site to got to "flatslist.php?order=M2&ordertype=ASC" after an add operation.
Go to table settings of flats-> go to return page of after add and put "flatslist.php?order=M2&ordertype=ASC".
NOTE:this should be a valid php string so put it with quotes as is. Just cahnge the flats for your table name and M2 for your field name, these are case sensitive as well

Now after adding a new record you should see page go to "flatslist.php?order=M2&ordertype=ASC" and the list should be sorted by M2 ascending


ceeronne
User
Posts: 22

Post by ceeronne »

Maybe i was little bit confusing in explanation.
User does not clic on any other field to sort by in patickular case, ofcourse they can but thats not the question question is when the M2 column is selected for sorting and when They add new record it should apear in its place by ASC sorting that they have selected M2 ASC but that is not the case its allways apears last.

Lets say that column M2 have values in its fields 35, 37 38 , 50, 100, 250, ...
and we add a new record wich has value in column M2=55 that row apears at the end so it looks like this 35, 37 38 , 50, 100, 250, 55, ...
but it should look like this 35, 37 38 , 50, 55, 100, 250, ...
so they must click twice on M2 to sort it again so the added row apears where it should,
My question was is therea a way (simple way) to added row apears where it should without having to sort it again to me its logical if I have clikced to sort it by the M2 ASC and when I add a new row (record) it should apear between upper and lower values not at the end without any sence.


kirondedshem
User
Posts: 642

Post by kirondedshem »

is therea a way (simple way) to added row apears where it should without having to sort it again
Yes:

  1. By setting that field in sort property of table settings of your table(such that it uses this by default (my first reply).
    OR
  2. Incase users are still allowed to sort by other columns by resetting the sort Order by passing it in return page (my second reply)

Thats what I meantioned in the first response. If you want the sorting to be done automatically minus you clicking the column to sorting. Then simply set the default sort orders for that table,
You can read about "Sort in Table setup of help menu", but in a summary:
-go to table settings of you table.
->Select sort->click button to open dialog(this sets what field you want to use to sort by deafult and what order)
->In the first drop down->select field M2->and ensure the order is on "A-Z(meaning ascending)"
->regenerate all files.

To check:
-log out and log ack in to clear all sessions
-now just go to the list of the page without doing anything else on it, you should see the coulumn header for M2 has an upward facing arrow(this means that this is the filed the list is currently sorted by in ascending order).
-Even after you add/edit this arrow should still be there and your desired order should appear.

HINT: I f you don't want them to change sort order then disable sort in field settings or just reset sort parameters after he adds.


Post Reply