Hello,
I am building a module in EE2 and am trying to get the AJAX pagination and table sorting working. I am using the members module as a model and have got my table headers high-lighting but my list of entries is not getting re-ordered.
I haven’t been able to find any documentation on using these features. Are they something you can easily plug in to, or does it require a lot of custom javascript?
I can see in the pagination settings on the members page this line:
"sPaginationType": "full_numbers",and this refers to a method in the main dataTables.js file. Do I need to create a equivalent method for my own set of data?
Any help would be hugely appreciated.
Many thanks,
Malcolm
the javascript package that enables the table sorting is (oddly enough) “tablesorter”. You’ll need to call the jquery object to request that it be loaded, I believe.
Something along these lines:
$this->EE->jquery->plugin(BASE.AMP.'C=javascript'.AMP.'M=load'.AMP.'plugin=tablesorter', TRUE);And then you’ll need to configure it with the settings object you require:
$this->EE->jquery->tablesorter('#my_addons_table', '{
textExtraction: "complex",
widgets: ["zebra"]
}');the documentation for tablesorter can be found here.
hope that helps.
Thanks Robin, I’ve got the Downloads module and opened it up.
I’m usually pretty good at decoding other peoples’ JavaScript, but this has got my stumped.
I have loaded in the JS library:
$this->EE->load->library('javascript');I load in the plugins:
$this->EE->cp->add_js_script(array('plugin' => 'dataTables'));
$this->EE->cp->add_js_script(array('plugin' => 'tablesorter'));I define the columns:
$this->EE->jquery->tablesorter('.mainTable', '{headers: {3: {sorter: false}}, widgets: ["zebra"], sortList: [[0,0]]}');I compile the JS
$this->EE->javascript->compile();Then when I try and resort my table the header highlights and the arrow shows in the right, but I get this JavaScript error.
Error: sortText is not defined
I’ve looked at other example and can’t see what I’m doing differently. Anyone got any ideas what’s missing?
Many thanks,
Malcolm
Ah- you want to use either datatables or tablesorter. Tablesort is a billion times easier- but it only works on a single page of data. (You can fidge it a bit- but that’s what it boils down to.)
datatables allows you to sort across multiple pages- using ajax. It also allows you to paginate. It’s also- a lot more complicated- mostly because you have the ajax calls.
So- try ditching table sorter. The take a look at edit_items_ajax_filter() - that basically constructs the ajax data array. Then look at ajax_filters - that generates the actual javascript. There’s no need to stick it in its own function like that- but I just like getting it out of my main function because it takes up so much room.
Like I say- WAY more complicated than tablesorter.
Thanks again Robin, I can see how these two are different now.
I have been using Member Groups as my example as this uses the ‘tablesorter’ method.
This was working fine but we have just upgraded our installation of EE to the latest build (v2.1.0 Build 20100805) and the Member Groups column sorting is no longer working.
I get a JavaScript error when I click any of the headers: sortText is not defined
Is anyone else having this problem?
Many thanks,
Malcolm
Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.