How to activate the closed Datagrids Searchbar via javascript

0
Follow up on my previous question: https://forum.mendix.com/link/questions/96215 which works fine, unless the searchbar of the datagrid is set to Closed. How can I activate the closed Datagrid's Searchbar via javascript? I have my javascript extended with: “if the searchbar is closed, open it and et the end close it” setTimeout( function(){ var sbar=document.querySelector('.mx-grid-searchbar'); var barStartedClosed=false; if(sbar.getAttribute('style').indexOf('display: none')<=0){ alert('bar is closed'); barStartedClosed=true; sbar.setAttribute('style', 'display:block'); } var n=dojo.query('.mx-selectbox')[0] var w=dijit.byNode(n) var i=w.items; i[0].selected=true; i[1].selected=true; i[2].selected=true; i[3].selected=true; i[4].selected=false; w._setItemsAttr(w.items) var grd=dijit.byNode(dojo.query('.gridShipmentOverview')[0]); grd.eventSearchActivated(new Event("click")); if(barStartedClosed==true){ sbar.setAttribute('style', 'display:block'); } }, 250) The if...<=0 works, then “sbar.setAttribute('style', 'display:block');” does show the Searchbar, but it is not active. How to make it active?
asked
2 answers
2

Hi Tim, try this snippet to open/close the search bar:

var gridNode = document.querySelector('.mx-grid');
var grid = dijit.registry.byNode(gridNode);
grid.actionToggleSearch();

 

answered
0

The endresult:

setTimeout(
    function(){
        // - Find the searchbar of a datagrid:
        // - If the statusbar is closed and inactive: open and activate it
        // - Set the tickmarks in the dropdown-selector
        // - Trigger the search to retrieve the objects
        // - Set the statusbar to its original setting
        var sbar=document.querySelector('.mx-grid-searchbar');
        var barStartedClosed=false;
        if(sbar.getAttribute('style').indexOf('display: none')<=0){
            var gridNode = document.querySelector('.mx-grid');
            var grid = dijit.registry.byNode(gridNode);
            grid.actionToggleSearch();
            barStartedClosed=true;
        }
        var n=dojo.query('.mx-selectbox')[0]
        var w=dijit.byNode(n)
        var i=w.items;
        i[0].selected=true;  // Pending
        i[1].selected=true;  // Accepted
        i[2].selected=true;  // Rejected
        i[3].selected=true;  // Completed
        i[4].selected=false; // Archived
        i[5].selected=false; // NoShow
        w._setItemsAttr(w.items)
        grid.eventSearchActivated(new Event("click"));
        if(barStartedClosed==true){
            grid.actionToggleSearch();
        }
    },
    250)

 

answered