Ej2 Grid: How to make the toolbar automatically spread into multiple rows (vertical)

Hello,

I have a lot of custom toolbar on my grid. The default behavior is the toolbar will be expanded horizontally like picture below:



My question, is it possible to spread the toolbar into multiple rows? so it will expanded vertically and the toolbar items will be all shown. So no need to navigate the toolbar using "kind of" left or right navigation button.

Thank  you in advance


Best regards,

Ismail


5 Replies

RR Rajapandi Ravi Syncfusion Team August 23, 2021 01:08 PM UTC

Hi ISMAIL, 

Greetings from Syncfusion support 

We have validated your reported query “is it possible to spread the toolbar into multiple rows” at our end. We have achieved your requirement with the help of overflowMode property of our Toolbar and for the same we have prepared the below sample.  

Please refer the below code example, sample and screenshot for more information. 

 
var grid = new ej.grids.Grid({ 
        dataSource: window.orderDataSource, 
        editSettings: { allowEditing: true, allowAdding: true, allowDeleting: true, mode: 'Normal', newRowPosition:'Top' }, 
        allowPaging: true, 
        pageSettings: { pageCount: 5 }, 
        toolbar: ['Add', 'Edit', 'Delete', 'Update', 'Cancel', 'Search', 'Print', 'ExcelExport', 'PdfExport', 'ColumnChooser', 'WordExport', { text: 'Custom button'}, {text: 'Copy'}, {text: 'Paste'}, {text: 'Open'}, {text: 'Close'}, {text: 'Cut'}, {text: 'Drag'}, {text: 'RowHeight'}], 
        actionBegin: actionBegin, 
       dataBound: function() { //dataBound event of Grid 
            grid.toolbarModule.element.ej2_instances[0].overflowMode = 'MultiRow'; //set the overflowmode as MultiRow to spread the toolbar item into multiple rows 
        }, 
        columns: [ 
            .  .  .  .  .  .  .  .  .  .  . 
            .  .  .  .  .  .  .  .  . .   . 
        ], 
    }); 
    grid.appendTo('#Grid'); 
 



Screenshot: 

 

Regards,
Rajapandi R 



IH ISMAIL HAMZAH replied to Rajapandi Ravi August 24, 2021 12:24 AM UTC

Hello Rajapandi,


Thank you for your support. I have try it out and its work, the toolbar layout become multi row. But come new problem, the paging is become missing? For your information, I calculate the height for the grid at grid created handler to fit di vertical size.


below image is before multi row toolbar: (highlight the paging is there)



below image is after multi row toolbar: (highlight the paging is missing)



do you have any recommendation for solving this problem? below is code to calculate the grid height:


        beforeDataBound: () => {

            grid.showSpinner();

        },

        dataBound: () => {

            grid.toolbarModule.element.ej2_instances[0].overflowMode = 'MultiRow';

            grid.hideSpinner();

        },

        excelExportComplete: () => {

            grid.hideSpinner();

        },

        created: () => {

            var gridHeight = ($(".pcoded-main-container").height()) - ($(".e-gridheader").outerHeight()) - ($(".e-toolbar").outerHeight()) - ($(".e-gridpager").outerHeight());

            grid.height = gridHeight;

        },


Thank you in advance


Best regard



RR Rajapandi Ravi Syncfusion Team August 24, 2021 09:22 AM UTC

Hi ISMAIL, 

Thanks for the update 

From your update, we could see that you are setting a grid height in the Created event of Grid to fit the vertical size. By setting overflowMode property as MultiRow in the dataBound event, the toolbar items spread into multiple rows vertically you don’t need to adjust the grid height in the Created event. Please refer the below code example and sample for more information. 

 
       dataBound: function() { //dataBound event of Grid 
            grid.toolbarModule.element.ej2_instances[0].overflowMode = 'MultiRow'; //set the overflowmode as MultiRow to spread the toolbar item into multiple rows 
        }, 
 
 


Screenshot: 

 

If we misunderstood anything wrongly, please share the below details that will be helpful for us to provide better solution. 

1)        Please share the details about why you are setting the Grid height in created event. Please share the details with detailed description. 

2)        Please share any issue reproducible sample or please modify the above sample as per your application structure and try to reproduce the issue. 

Regards, 
Rajapandi R 



IH ISMAIL HAMZAH replied to Rajapandi Ravi August 24, 2021 11:01 AM UTC

Hello Rajapandi,


Thank you for your update. I need to recalculate the grid height because I need precise grid height, why am doing this? this is because by design, I have turned off the browser vertical scroll bar. I'm doing that because I want consistent and focused UI to grid. So when user navigating the data, he/she only use grid vertical scroll bar which result very nice UI because the static header and the grid column title did not move around.


Basically I got the grid height by calculating total height minus header height minus toolbar height minus pager height. The formula is already OK, but it seems I should put the calculation in another place not in grid created event? Place where the multi row toolbar height already known in advance.


Below is normal situation with single row toolbar:



Best regards,

Ismail



RR Rajapandi Ravi Syncfusion Team August 25, 2021 12:28 PM UTC

Hi ISMAIL, 

Thanks for the update 

We have checked your query and we could see that you are performing a calculation and set the height to the Grid in Created event. To achieve your requirement, we suggest you set your calculated height in dataBound event of Grid. Please refer the below code example and sample for more information. 
 
 
load: function() { 
            flag = true; 
        }, 
        dataBound: function() { 
            if(flag) { 
                flag = false; 
            var container = document.getElementsByClassName('e-resizable')[0].offsetHeight; 
            var header = document.getElementsByClassName('e-gridheader')[0].offsetHeight; 
            var toolbar = document.getElementsByClassName('e-toolbar')[0].offsetHeight; 
            var pager = document.getElementsByClassName('e-gridpager')[0].offsetHeight; 
            grid.height = container - header - toolbar - pager; 
           
             
            grid.toolbarModule.element.ej2_instances[0].overflowMode = 'MultiRow'; 
       


Rajapandi R 



Loader.
Up arrow icon