jqgrid, export to excel (with current filter post data) in an asp.net-mvc site

前端 未结 3 1165
执笔经年
执笔经年 2021-01-17 03:53

i have an asp.net-mvc web page and i am using jqgrid on the front end. i want to have an export to excel button that will export the current set of data (based on the curr

3条回答
  •  难免孤独
    2021-01-17 04:39

    You could put hidden fields inside the Export to Excel form:

    @using (Html.BeginForm(new { action = "ExportToExcel" }))
    {
        @Html.Hidden("sidx")
        @Html.Hidden("sord")
        @Html.Hidden("page")
        @Html.Hidden("rows")
        
    }

    and populate them upon form submission based on the current values:

    $('form').submit(function () {
        var grid = $('#list');
        var sortname = grid.getGridParam('sortname');
        var sortorder = grid.getGridParam('sortorder');
        var page = grid.getGridParam('page');
        var rows = grid.getGridParam('rowNum');
        $('#sidx').val(sortname);
        $('#sord').val(sortorder);
        $('#page').val(page);
        $('#rows').val(rows);
    });
    

    This way the ExportToExcel controller action will take those parameters and be able to filter the list.

提交回复
热议问题