cancel
Showing results for 
Search instead for 
Did you mean: 

Alfresco.util.DataTable and sorting

loftux
Star Contributor
Star Contributor
I've got paging working in my DataTable, but it breaks when trying to do sorting.
Sorting itself works, but if paging is introduced, the paging breaks (ie is ignored) when sorting.

DataTable paging send paging arguments
<url>&skipCount=0&maxItems=10
but sorting uses defaults
<url>&sort=name&dir=desc&startIndex=0&results=500

Is there a way to configure DataTable widget to use/replace startIndex and results with skipCount and maxItems respectively?
4 REPLIES 4

loftux
Star Contributor
Star Contributor
And it says in alfresco.js about the DataTable: "Sorting support is not yet implemented".

Guess I have to find another way to do this.

erikwinlof
Confirmed Champ
Confirmed Champ
Hi,

Yes unfortunately sorting hasn't been added yet and overriding the functions needed to do that isn't very easy since they are inline methods 😞
Our aim is to use the Alfresco.util.DataTable for all (or at least most) of our lists and tables in the future and when that is done sorting will absolutely be added.

loftux
Star Contributor
Star Contributor
I ran into this problem again, and found a way to solve it. Using this method you can now enable sortin by clicking the header.
In the config section for your dataTable, add generateRequest and bind it to a function.
                           config : {
                              MSG_EMPTY : this.msg("message.nosearchresults"),
                              dynamicData : true,
                              generateRequest : this.bind(this.sortingResolver)
                           }
This functions to me looks like
                  sortingResolver : function Avtal_sortingResolver(sort, dataTable)
                  {
                     var url = '?', page = 0;
                     // First store the sort options
                     this.options.sortDir = (sort.sortedBy.dir === YAHOO.widget.DataTable.CLASS_DESC) ? "desc" : "asc";
                     this.options.sortKey = sort.sortedBy.key;
                     // Calculate the page offset. This is a bit odd, but works
                     page = (sort.pagination.page - 1) * sort.pagination.rowsPerPage;
                     url += this.pagingResolver(page, sort.pagination.rowsPerPage);
                     url += '&' + this.filterResolver(this.widgets.pagingDataTable.currentFilter);
                     if (Alfresco.logger.isDebugEnabled())
                     {
                        Alfresco.logger.debug("\nSorting url: " + url);
                        Alfresco.logger.debug("\nSorting pagination: " + page + ' ' + sort.pagination.rowsPerPage);
                     }
                     return url;
                  },
This function in turn calls the pagingResolver and filterResolver to get the full url for the xhr request. What you need to add to those functions of course depends on how you are using the datatable. But this is the basics of what you need to do.
You also have to enable sorting per column, set sortable to true, this is a snippet of the config
                     this.widgets.pagingDataTable = new Alfresco.util.DataTable({
                        dataTable : {
                           container : this.id + "-searchTable",
                           columnDefinitions : [ {
                              key : "cm:name",
                              label : "Namn",
                              sortable : true,
                              formatter : this.bind(this.renderName)
                           }, {
                              key : "cm:title",
                              label : "Titel",
                              sortable : true,
                              formatter : this.bind(this.renderTitle)
                           },

erikwinlof
Confirmed Champ
Confirmed Champ
Nice one! Feel free to create a jira for it and submit the code and we'll try put it in as soon as possible!

Cheers, Erik