New record, new sort sequence. Editor - server-side - PHP.

New record, new sort sequence. Editor - server-side - PHP.

tangerinetangerine Posts: 3,350Questions: 37Answers: 394

I've seen posts about keeping a newly added row at the top of the table, but my preference would be to trigger a sort by primary (auto-incremented) key on "Create".
That's because I'm often working in alphabetical order, but then creating a new record and having to manually re-sort to get at the new record. Not a disaster, but a programmed re-sort for every "Create" would be useful. Any suggestions?
Thanks in advance.

This question has an accepted answers - jump to answer

Answers

  • colincolin Posts: 15,143Questions: 1Answers: 2,586

    On this re-sort, would you want to go to the location of the newly added record? You could use one of the Editor events, such as postCreate to initiate the search, and if you're using Scroller, you could use row().scrollTo().

    Colin

  • tangerinetangerine Posts: 3,350Questions: 37Answers: 394

    Thanks, Colin. But the point is that a re-sort by primary key would give me the new record at the top.
    I suspect that it's not possible, from browsing forum and docs. But it would be useful if for example a postCreate could override the current order.

  • allanallan Posts: 61,716Questions: 1Answers: 10,108 Site admin
    Answer ✓

    The row().show() plug-in might be one option? That would retain current sorting while also jumping the paging to the new row - that would be triggered in postCreate.

    The other option would be to have the primary key in a hidden column and then apply order() to that column in postCreate as you say.

    Allan

  • tangerinetangerine Posts: 3,350Questions: 37Answers: 394

    Somehow I had got the impression that I couldn't use postCreate.
    Turns out I can:

    oEditor.on('postCreate', function (e, json, data) {
        oTable
            .column( '0:visible' )
            .order( 'desc' )
            .draw();
    });
    

    Seems to be working fine, unless you can see anything wrong with it.
    Thank you.

  • tangerinetangerine Posts: 3,350Questions: 37Answers: 394

    My previous post includes one of my most consistent failings: I copy and paste a "function" line of code and leave the parameters in place even though I'm not using them.
    Onwards and upwards...

  • colincolin Posts: 15,143Questions: 1Answers: 2,586

    Heh, we all do that :)

This discussion has been closed.