Add custom datalist filter quickly

cancel
Showing results for 
Search instead for 
Did you mean: 

Add custom datalist filter quickly

davidm
Active Member II
0 0 1,609

This post will allow you create an additional filter to your datalist in a simple and fast way.

Requirements:
  • AIO project or failing [your-project]-platform and [your-project]-share
  • Alfresco SDK 3.0

Summary:
  1. Overwrite js [org.alfresco.slingshot.datalists.data.post] webscript files
  2. Overwrite config [org.alfresco.components.data-lists.filter.get] webscript file

***

Step 0:

First of all create your AIO project in your IDE.

Step 1:

Copy data.post.json to your platform project path:

src > main >  resources > alfresco > extension > templates > webscripts > org > alfresco > slingshot > datalists

This will overwrite the [org.alfresco.slingshot.datalists.data.post] js webscript file.

Edit data.post.json file and add else if() block in the getData() function:

(...)
if (filter == null || filter.filterId == "all")
{
   ...
}
}
else if (filter.filterId == "MyCustomFilter")
{
     // Use non-query method
     var parentNode = parsedArgs.listNode;
     if (parentNode != null)
     {
         var pagedResult = parentNode.childFileFolders(true, false, Filters.IGNORED_TYPES.concat(Filters.IGNORED_ASPECTS), 1, -1, REQUEST_MAX, "cm:name", true, null);
         allNodes = pagedResult.page;
     }
}
else
{

(...)

We have modified childFileFolders() function for a simple test but at this point you could implement your request to the repository saving all your response items in allNodes var.

Step 2:

Copy  filter.get.config.xml to your share project path:

src > main > resources > alfresco > web-extension > site-webscripts > org > alfresco > components > data-lists

This will overwrite the [org.alfresco.components.data-lists.filter.get] config webscript file.

Edit filter.get.config.xml file and add <filter tag line:

<filters>
    ....
    <filter id="MyCustomFilter" label="Custom filter label" />
</filters>

This new tag will show a new filter in the left datalist page menu.

Extends:

If you want implement a complex repository query for your filter  check out and overwrite evaluator.lib.js and filters.lib.js files in platform project and modify its nested functions.

I hope it saved you time and have a nice day

DavidMM