We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

How to pass Menu Filter value to a excel export header Template

It's been somewhat of a struggle but I'm trying to capture the the filter applied to rows in my grid to set a header value in my excel export template. I can get the Search bar value but not the column filter.

My grid- 
<ejs-grid id="Grid" dataSource="@Model.Package_Log" allowExcelExport="true" toolbarClick="toolbarClick" dataBound="dataBound" width="1193"
              toolbar="@(new List<string>() { "ExcelExport","ColumnChooser","Search" })"
              showColumnChooser="true"
              allowPaging="true" allowSorting="true" allowResizing="true" allowFiltering="true" allowGrouping="false" showColumnMenu="true">
        <e-grid-filterSettings type="Menu" showFilterBarStatus="true" operators="@( new { stringOperator = @Model.operators})"></e-grid-filterSettings>
        <e-grid-pagesettings pageCount="20" pageSize="14"></e-grid-pagesettings>
        <e-grid-selectionsettings type="Multiple"></e-grid-selectionsettings>
        <e-grid-columns>
            <e-grid-column headerText="Package Name" field="PackageName" textAlign="Left"></e-grid-column>
            <e-grid-column headerText="Sequence" field="PackageSequence" textAlign="Left" visible="false"></e-grid-column>
            <e-grid-column headerText="Sequence Start" field="SequenceStart" textAlign="Left" headerTemplate="#datetemplatestart" customFormat="@(new { type= "dateTime", format= "MM/dd/yyyy hh:mm:ss a" })"></e-grid-column>
            <e-grid-column headerText="Sequence End" field="SequenceEnd" textAlign="Left" customFormat="@(new { type= "dateTime", format= "MM/dd/yyyy hh:mm:ss a" })"></e-grid-column>
            <e-grid-column headerText="Log Entry" field="LogMessage" textAlign="Left"></e-grid-column>
            <e-grid-column headerText="Time Stamp" field="LogTimeStamp" textAlign="Left" customFormat="@(new { type= "dateTime", format= "MM/dd/yyyy hh:mm:ss a" })" visible="false"></e-grid-column>
            <e-grid-column headerText="Status" field="SequenceStatus" textAlign="Left" visible="false"></e-grid-column>
            <e-grid-column headerText="Error Number" field="SequenceErrNumber" textAlign="Left" visible="false"></e-grid-column>
            <e-grid-column headerText="Error" field="SequenceErrDesc" textAlign="Left" visible="false"></e-grid-column>
        </e-grid-columns>
    </ejs-grid>

And my excel header template - the Search Bar value comes through just fine... But I'm not sure how to get at the column filter value?:

<script>
    function toolbarClick(args) {
        var gridObj = document.getElementById("Grid").ej2_instances[0];

        var searchval = document.getElementById("Grid_searchbar").value;
        var filterval = document.getElementById("Grid_colmenu_Filter").value;
        if (searchval == "" || searchval.length == 0 || searchval == null) {
            searchval = "All Rows No Searched filter";
        }
        else
        {
            searchval = " Rows Searched on " + searchval;
        }

        if (filterval == "" || filterval.length == 0 || filterval == null) {
            filterval = "All Rows No Filter";
        }
        else {
            filterval = " Rows Filtered on " + filterval;
        }

        var excelExportProperties = {
            includeHiddenColumn: true,
            
            header: {
                    headerRows: 4,
                    rows: [
                        { cells: [{ colSpan: 4, value: "SSIS Package Logs", style: { fontColor: '#C67878', fontSize: 20, hAlign: 'Center', bold: true, } }] },
                        { cells: [{ colSpan: 4, value: "[From ssisCorePortal " + searchval + " " + filterval + "]", style: { fontColor: '#C67878', fontSize: 15, hAlign: 'Center', bold: true, } }] },
                        { cells: [{ colSpan: 4, value: "Exported on: @DateTime.Now", style: { fontColor: '#C67878', fontSize: 15, hAlign: 'Center', bold: true, } }] },
                    ]
                },
            footer: {
                    footerRows: 4,
                    rows: [
                        { cells: [{ colSpan: 4, value: "Thank you for your business!", style: { hAlign: 'Center', bold: true } }] },
                        { cells: [{ colSpan: 4, value: "!Visit Again!", style: { hAlign: 'Center', bold: true } }] }
                    ]
                }
        };
        if (args.item.id === 'Grid_excelexport') {
            //gridObj.showSpinner();
            gridObj.excelExport(excelExportProperties);
        }

        if (args.item.id == "Grid_pdfexport") {
            //gridObj.showSpinner();
            gridObj.pdfExport();
        }

    }


3 Replies

SS Seeni Sakthi Kumar Seeni Raj Syncfusion Team July 15, 2019 11:46 AM UTC

Hi Scott,  

Greetings from Syncfusion.  

We could see you would like to collect the filtered columns with the respective values. This can be collected using the filterSettings.columns. Refer to the following code example.  

<ejs-grid id="Grid" dataSource="@ViewBag.DataSource" allowFiltering="true" toolbar="@(new List<string>() { "ExcelExport" })" toolbarClick="toolbarClick"> 
    <e-grid-filterSettings type="Menu"></e-grid-filterSettings> 
        . ..  
                 . . . 
</ejs-grid> 
 
<script>   
    function toolbarClick(args) { 
        var filter = ej.data.DataUtil.select(this.filterSettings.columns, ['field', 'value']), str = ""; 
        for (var f = 0; f < filter.length; f++) { 
            str = str + filter[f].field + " && " + filter[f].value; 
            str = str + ((f + 1) === filter.length ? "" : " | "); 
        } 
        console.log(str); 
    } 
</script> 

Regards,  
Seeni Sakthi Kumar S. 



SE Scott Edwards July 15, 2019 01:51 PM UTC

Thank you Seeni. That's what I was looking for.

Scott



SS Seeni Sakthi Kumar Seeni Raj Syncfusion Team July 16, 2019 05:41 AM UTC

Hi Scott,  

Thanks for the update. We are happy to hear that your requirement has been achieved and you are good to go.  

Regards,  
Seeni Sakthi Kumar S. 


Loader.
Live Chat Icon For mobile
Up arrow icon