What are the options for sortable tables?

What are the options for sortable tables?

by Howard Miller -
Number of replies: 8
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

Is there anything in Moodle to create a sortable, paginated table? 

I've used html_table quite a bit, but that only seems to handle simple tables as it stands. 

I've also used flexible_table() but beyond a certain point is incomprehensible. It obviously does have some sorting facilities but appears to be linked directly to SQL queries. In addition things like sorting direction are not exposed in the URL, they are buried in the session.

There doesn't seem to be anything to provide sorting and pagination for simple tables full of text (like) data or that expose the current column/direction state to enable this to be done outside the table API.

Or am I completely missing something? wink

Average of ratings: -
In reply to Howard Miller

Re: What are the options for sortable tables?

by Darko Miletić -

It is either flexible_table or nothing. What exactly can you not do with flexible_table?

Average of ratings: Useful (1)
In reply to Darko Miletić

Re: What are the options for sortable tables?

by Darko Miletić -

To rectify a bit, if you have arbitrary information coming from other sources than database you can turn to JavaScript. In Moodle prior to 2.9 you can try using YUI Table or in 2.9+ try jQuery and one of it's table plugins. There you would have full range of freedom to do whatever you want.

Average of ratings: Useful (1)
In reply to Darko Miletić

Re: What are the options for sortable tables?

by Howard Miller -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

Yes - that might be the simplest answer. Or I might just wrap something of my own around html_table. 

I'm just venting a bit. There are tables all over the place in the Moodle UI and their handling is surprisingly inconsistent. 

In reply to Howard Miller

Re: What are the options for sortable tables?

by Séverin Terrier -
Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Testers Picture of Translators

Hi,

That remembers me i created MDL-37551 nearly 3 years ago, talking about that...

Séverin

In reply to Séverin Terrier

Re: What are the options for sortable tables?

by Marcus Green -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers

I recently had a play with this plugin that makes using dataTables easier with Moodle tables

https://moodle.org/plugins/tool_datatables

I tried the suggested example with the ad-hoc queries plugin and it made the columns sortable. Strangley it gave no indication they were sortable, but clicking on the header did the sorting thing very nicely.

In reply to Darko Miletić

Re: What are the options for sortable tables?

by Howard Miller -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

Unless I am missing something, flexible table does not expose the sort direction in the URL when you click a heading. That's stored in the session making not quite as 'flexible' as it might be. 

In reply to Howard Miller

Re: What are the options for sortable tables?

by Darko Miletić -

Moodle and inconsistencies? I think this video tells it all