How can I set the sort order of the SQL query?

How can I set the sort order of the SQL query?

th3t1ckth3t1ck Posts: 228Questions: 37Answers: 1

I have the following in my server-side php and I would like to sort it by id and not month...

$out=Editor::inst( $db, 'lk_months', 'id')
->field(
Field::inst( 'id' ),
Field::inst( 'month' )
)
->process($_POST)
->json();

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 61,446Questions: 1Answers: 10,054 Site admin

    The ordering is does automatically in the DataTable. Do you have id shown as a column in your DataTable? Can you use the debugger to give me a trace please - click the Upload button and then let me know what the debug code is.

    Thanks,
    Allan

  • th3t1ckth3t1ck Posts: 228Questions: 37Answers: 1

    Hi Allan, What I meant was can I do a sort ASC/DESC when the database is queried. Clicking on the columns sorts fine but the months are sorting from April to September and I would like them sorted January-December. I didn't want the id shown in the table however it does sort it the way I'd like when I include the id in the table
    .
    Great product by the way. I am so glad I found it and purchased it.

  • allanallan Posts: 61,446Questions: 1Answers: 10,054 Site admin
    Answer ✓

    Assuming you are using client-side processing, then using a sorting plug-in would be the way to do it. I had thought that there was one for month names, but I can't see it. The moment plug-in is a good option if you want to use that for flexible formatting.

    If you are using server-side processing, then its the server that does the ordering (i.e. the SQL database), so assuming its a date/time field, it would just work automatically.

    Allan

  • th3t1ckth3t1ck Posts: 228Questions: 37Answers: 1

    Ok. Thank you Allan. I'll give those a try.

This discussion has been closed.