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

前端 未结 3 1169
执笔经年
执笔经年 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:35

    What I have done is put the gridstate into the cache each time data is requested, then I do the export to excel using the gridState. There are examples of this somewhere on the jqGrid site:

    //this fragment in GetData method
    Session["ExceptionGridState"] = gridModel.ExceptionGrid.GetState(true);
    

    Then when the export is called:

    public ActionResult ExportToExcel_CurrentData()
    {
      var gridModel = new ExceptionJqGridModel();
      var grid = gridModel.ExceptionGrid;
    
      // call the ExportToExcel built-in method
      JQGridState gridState = Session["ExceptionGridState"] as JQGridState;
      gridState.CurrentPageOnly = false;
      grid.ExportToExcel(SourceQuery(),
            String.Format("SomeDatasetName_Filtered_{0:yyyymmddhhmm}.xls", 
                DateTime.Now), 
            gridState);
    
    return View();
    

    }

    This works for me.

提交回复
热议问题