Link to filtered view of list

I'm trying to create Module Action Links in the Meganav that link to different filtered views of the same module.

I've created some custom filters on the Accounts list view, and I've figured out how to add custom Module Actions Link buttons.

This was my most recent attempt, but the route doesn't work:

$viewdefs[$module_name]['base']['menu']['header'][] = array(
'label' =>'LNK_ACCOUNTS_SCO',
'acl_module'=>$module_name,
'icon' => 'fa-bars',
'route'=>'#Accounts?filter%5B0%5D%5Baccounttype%5D%5B%24in%5D%5B%5D=Subsidiary%20Organisation',
);

Can anyone advise the best approach here please?

Parents
  • Hi ,

    It's interesting to see what you wanted to achieve but it doesn't work out of the box. 

    But with a little coding, you can get it to work. There could be different ways to make it work, but here is one:

    So the filters are setup as part of filter layout - and the core layout code is present in clients/base/layouts/filter/filter.js which is the file that you have to extend in custom folder.

    You will see a method called handleFilterChange - which will be called when a layout is loaded. Here are the first few lines of this method:

    var filter, editState = this.retrieveFilterEditState();

    // Figure out if we have an edit state. This would mean user was editing the filter so we want him to retrieve
    // the filter form in the state he left it.
    filter = this.filters.collection.get(id) || app.data.createBean('Filters', {module_name: this.moduleName});
    if (editState && (editState.id === id || (id==='create' && !editState.id))) {
    filter.set(editState);
    } else {
    editState = false;
    }

    What is happening here is that - the code is trying to retrieve the most recent filter from the cache. This is where we could possibly write our own code, where if the "editState" is null (i.e no filters), you can substitute with your own filter. Eg:

    if (!editState && (/* YOUR CRITERIA HERE */)) {
    id = 'create';
    editState = {
    "editable": true,
    "deleted": false,
    "filter_definition": [
    {
    "accounttype": {
    "$in": [
    "Subsidiary Organisation"
    ]
    }
    }
    ]
    };
    }

    This change will become common for all layouts - here you can write your own code to retrieve filter from the URL and set it accordingly. 

Reply
  • Hi ,

    It's interesting to see what you wanted to achieve but it doesn't work out of the box. 

    But with a little coding, you can get it to work. There could be different ways to make it work, but here is one:

    So the filters are setup as part of filter layout - and the core layout code is present in clients/base/layouts/filter/filter.js which is the file that you have to extend in custom folder.

    You will see a method called handleFilterChange - which will be called when a layout is loaded. Here are the first few lines of this method:

    var filter, editState = this.retrieveFilterEditState();

    // Figure out if we have an edit state. This would mean user was editing the filter so we want him to retrieve
    // the filter form in the state he left it.
    filter = this.filters.collection.get(id) || app.data.createBean('Filters', {module_name: this.moduleName});
    if (editState && (editState.id === id || (id==='create' && !editState.id))) {
    filter.set(editState);
    } else {
    editState = false;
    }

    What is happening here is that - the code is trying to retrieve the most recent filter from the cache. This is where we could possibly write our own code, where if the "editState" is null (i.e no filters), you can substitute with your own filter. Eg:

    if (!editState && (/* YOUR CRITERIA HERE */)) {
    id = 'create';
    editState = {
    "editable": true,
    "deleted": false,
    "filter_definition": [
    {
    "accounttype": {
    "$in": [
    "Subsidiary Organisation"
    ]
    }
    }
    ]
    };
    }

    This change will become common for all layouts - here you can write your own code to retrieve filter from the URL and set it accordingly. 

Children
No Data