Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Fuel Table Sort package
  • TableSort class Almost every CMS have tables that need sorting on all or some columns, so i decided to create class, that helps create header rows and handles everything. Based on same principles as Pagination class.
    Cookie support.
    Full template config.
    Works also in combination with Pagination class. Example:
    http://darklow.fuel.first.lv/tablesort Github:
    https://github.com/darklow/fuel-tablesort
  • Ran into one issue with the package. The sort vars seem to be global. So if you have multiple views using this and sort on one column in one view and switch to a different view that one will try to sort by the same sort_by. This causes a SQL error if the column doesn't exist in the table, obvious. For now, I'm just doing a check to see if a sort_by is set and if it is in an acceptable field list.
  • Looks like this might come in very handy! It suffers from the same issue as the pagination class though, in that the location of the control variables in the URI are hardcoded. So you run into issues when your URI has to be http://darklow.fuel.first.lv/this/that/tablesort/1/name-desc.
  • Thanks, glad you find it handy
    WanWizard wrote on Tuesday 11th of October 2011:
    It suffers from the same issue as the pagination class though, in that the location of the control variables in the URI are hardcoded. So you run into issues when your URI has to be http://darklow.fuel.first.lv/this/that/tablesort/1/name-desc.

    Well it is not exactly hardcoded. I left config parameter: base_url outside the class, so you can control it with the config. You can always auto-detect needed url using URI class. I could put autodetect in the class, but it will never satisfy 100% of all the users, that is why also in Pagination class and here you can specify location url by yourself. For example if your url is /items/2/ class could never know if 2 is pagination and should be striped out, or it is some kind of a section and should be there and final url should be /items/2/$page/$sort. Changed hardcoded string to URI function, so that people don't confused
    'base_url' => '/'.URI::segment(1).'/',
  • I'd suggest to use http://tablesorter.com/docs/#Demo for "small" tables (because you're loading all the results in one time)
  • Peter Wiggers wrote on Thursday 13th of October 2011:
    I'd suggest to use http://tablesorter.com/docs/#Demo for "small" tables (because you're loading all the results in one time)

    You mean IF you are loading all results in one time, then yes, you can use local javascript sorting, otherwise if you are using database queries (as in my example) you will need to use Pagination and also TableSort class...
  • Thats why I wrote "the same issues as the pagination class". Ideally, you should be able to define that URI segment x is your page, and URI segment y the sort order. That way it doesn't matter what the URI looks like, and every controller can define the correct values for x and y. For constructing URI's, it also means that you can insert placeholders in case x is larger than the number of segments of the base_url (minus 1). I've been thinking about implementing this for pagination, but haven't had the time to do so.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion