簡體   English   中英

在 JqGrid 中顯示超過 10000 條記錄

[英]Display More then 10000 records in JqGrid

在我的數據庫表中,我有超過 30,000 條記錄,在這里我試圖在JqG​​rid 中顯示這些記錄,在這里我只顯示了 900 條記錄,我如何在 JqGrid 中顯示所有記錄,在這里我附上了我的代碼。

    <script type="text/javascript">

        $(function () {
            $("#dataGrid").jqGrid({
                url: 'Default.aspx/GetDataFromDB',
                datatype: 'json',
                mtype: 'POST',
                overflow:'visible',

                serializeGridData: function (postData) {
                    return JSON.stringify(postData);
                },

                ajaxGridOptions: { contentType: "application/json" },
                loadonce: true,
                colNames: ['AOfficeKey', 'AChartNumber', 'APatientName', 'AVisit#'],
                colModel: [
                                { name: 'AOfficeKey', index: 'AOfficeKey', width: 80 },
                                { name: 'AChartNumber', index: 'AChartNumber', width: 150 },
                                { name: 'APatientName', index: 'APatientName', width: 160 },
                                { name: 'AVisit#', index: 'AVisit#', width: 160 }



                ],
                pager: '#pagingGrid',

                rowNum: 100,
                height: 300,
                width:600,
                rowList: [10, 100, 1000, 10000],
                gridview: true,

                viewrecords: true,
                gridview: true,
                jsonReader: {
                    page: function (obj) { return 1; },
                    total: function (obj) { return 1; },
                    records: function (obj) { return obj.d.length; },
                    root: function (obj) { return obj.d; },
                    repeatitems: false,
                    id: "0"
                },

            });
        });    

    </script>
</head>
<body style="font-family: Arial; font-size: 10pt">
    <table style="border: solid 1px ; width: 100%; vertical-align: central;">
        <tr>
            <td style="padding-left: 20px; padding-top: 20px; padding-bottom: 20px; font-family: 'Times New Roman'; font-weight: bold; font-size: 20pt; color: chocolate;">
            </td>
        </tr>
        <tr>
            <td style="text-align: center; vertical-align: central; padding: 100px;">
                <table id="dataGrid" style="text-align: center; width: 100%;"></table>
                <div id="pagingGrid"></div>
            </td>
        </tr>
    </table>

C# 代碼是

   [WebMethod]
    public static List<Dictionary<string, object>> GetDataFromDB()
    {
        DataTable dt = new DataTable();
        using (SqlConnection con = new SqlConnection(@"Data Source=Abc;Database=Training;User Id=sa;Password=abc;"))
        {
            using (SqlCommand cmd = new SqlCommand("SELECT  * AOfficeKey,AChartNumber, APatientName,AVisit# from adjs", con))
                //("SELECT ID,Client,Location,Address FROM AClients ", con))
            {
                con.Open();
                SqlDataAdapter da = new SqlDataAdapter(cmd);
                da.Fill(dt);
                System.Web.Script.Serialization.JavaScriptSerializer serializer = new System.Web.Script.Serialization.JavaScriptSerializer();
                List<Dictionary<string, object>> rows = new List<Dictionary<string, object>>();
                Dictionary<string, object> row;
                foreach (DataRow dr in dt.Rows)
                {
                    row = new Dictionary<string, object>();
                    foreach (DataColumn col in dt.Columns)
                    {
                        row.Add(col.ColumnName, dr[col]);
                    }
                    rows.Add(row);
                }
                return rows;
            }
        }
    }

我試過你的代碼,它沒有錯誤。 但是,為了從服務器加載大量數據,您需要在使用 json 序列化時增加允許的 JSON 大小。 為了在 <configuration> 標記中將以下代碼傳遞到您的 web.config 中:

<system.web.extensions>
    <scripting>
      <webServices>
        <jsonSerialization maxJsonLength="50000000"/>
      </webServices>
    </scripting>
</system.web.extensions>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM