0

I made a Jqgrid for dispalying database with filterToolbar option using Asp.net Now As per my need i want the filtered data to get exported into .excel formate ..

Here i am posting my code....

var categoriesStr = ":All;1:vikas;2:Ankur";
    $(function () {
        $("#UsersGrid").jqGrid({
            url: 'jqGridHandler.ashx',
            datatype: 'json',
            height: 250,
            colNames: ['UserID', 'UserName', 'FirstName', 'MiddleName', 'LastName', 'EmailID'],
            colModel: [
                    { name: 'UserID', index: 'UserID', width: 100, sortable: true },
                    { name: 'UserName', width: 100, sortable: true, formatter: 'select',stype: 'select', searchoptions: { sopt: ['eq'], value: categoriesStr} },
                    { name: 'FirstName', width: 100, sortable: true },
                    { name: 'MiddleName', width: 100, sortable: true },
                    { name: 'LastName', width: 100, sortable: true },
                    { name: 'EmailID', width: 150, sortable: true },
                   // { name: 'ContactNo', width: 150, sortable: true },
                    //{ name: 'Address', width: 150, sortable: true }
                ],
            rowNum: 10,
            rowList: [10, 20, 30],
            pager: '#UsersGridPager',
            sortname: 'UserID',
            viewrecords: true,
            sortorder: 'asc',
            autowidth:true

            //caption: 'JSON Example'
        });

        $("#UsersGrid").jqGrid('navGrid', '#UsersGridPager', { edit: false, add: false, del: false,search:false });

       $("#UsersGrid").jqGrid('filterToolbar', { stringResult: true, searchOnEnter: true, defaultSearch: 'cn' });
$("#UsersGrid").jqGrid('navButtonAdd', '#UsersGrid-pager',{ caption: "Filter", title: "Toggle Searching Toolbar",buttonicon: 'ui-icon-search',onClickButton: function () {$("#UsersGrid")[0].toggleToolbar(); }
});

plz Guys Help me to complete my task .Thanx in advance...

vikas
  • 101
  • 1
  • 3
  • 16

1 Answers1

0

I think that you should read UPDATED part of the answer. You can download the demo project which I created for the answer. I recommend to use Open XML SDK 2.5 (or Open XML SDK 2.0 if you can use .NET 3.5 only) to export data to excel. More common way of usage HTML table as pseudo-Excel export can produce wrong import on data. I described such problems in details in another answer.

I suppose that UPDATED part of the answer provides exactly what you need (or you can easy modify the demo to have the solution which you need).

Community
  • 1
  • 1
Oleg
  • 220,925
  • 34
  • 403
  • 798