cancel
Showing results for 
Search instead for 
Did you mean: 

Alfresco.util.DataTable and search maxItems

loftux
Star Contributor
Star Contributor
Hi,

I'm using the Alfresco.util.DataTable and trying to get paging to work.
In the DataTable widget, maxItems is the max number of rows per page, in Alfresco javascript search object it is the maxItems to return in a search:
  var paging =
  {
     maxItems: 10,
     skipCount: 0
  };
That is, on the server side if I set the maxItems, the search will stop when maxItems is reached. But returning this to the DataTable, the DataTable has no way of knowing that there actually is a larger set available, and there is no paginater pages created.
So if I only use maxItems for the DataTable, and set
  var paging =
  {
     maxItems: 100, //Can possibly skip entirely
     skipCount: 10 //from passed in DataTable, page 2 of max 10 per row
  };
in this case, I also return the max number of hits to the DataTable. Paginator is created.
But if there is a total of 100 hits, I get 90 items returned.

What I'm missing is a maxRowItems in the javascript search API.
I guess I can emulate that in javascript by just returning the first 10 (it that is what I want per row).

on further testing I resolved paging:
In you webscript, always return searchresults.length+scipcount to get actual number of hits, since search subtracts the scipcount from total hits (correctly so)
This would be part of your json return
"paging": 
   {
      "totalItems": ( searchresults.length+scipcount),
      "maxItems": 10,
      "skipCount": (the current value of skipped items)
   }
Also, loop the searchresults and only return the first maxItems, so that you do not return an an unnecessary large result set.
1 REPLY 1

erikwinlof
Confirmed Champ
Confirmed Champ
Hi,

Yes we should definitively add paging to the search webscript, which of course would be the best way to solve the problem :-).
I have filed to a jira for this: http://issues.alfresco.com/jira/browse/ETHREEOH-3416

Perhaps it may interest you that the task-instances webscript is a good example of how "paging" will work in the future, a pattern that:
- also matches the CMIS paging strategy and
- will match the Alfresco.util.DataTable's default config.

This is how it looks:

"paging":
{
   "totalItems": searchresults.length, // The total number of items that match the search term criterias (no matter what the skipCount or maxItems is set to)
   "maxItems": 10, // The maximum number of items to return in a request (
   "skipCount": 0 // The item index position to start returning items from (in other words NOT a "page number")
}

… so I would say that "maxItems" in this strategy actually is the "maxRowItems" you're looking for. An example of a request asking for tasks is:

GET http://localhost:8081/share/proxy/alfresco/api/task-instances?authority=admin&properties=bpm_priorit...

…which gives you the following response for a use that has 2 tasks….

200 OK
{
   "data": [
      { "id": "jbpm$5", … },
      { "id": "jbpm$3", …}
   ],
   "paging":
   {
      "totalItems": 2,
      "maxItems": 50,
      "skipCount": 0
   }
}

Cheers, Erik