【问题标题】:Freezing column in jqgrid is not workingjqgrid中的冻结列不起作用
【发布时间】:2012-08-22 07:08:41
【问题描述】:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Freeze.aspx.cs" Inherits="Freeze" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title>Untitled Page</title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <link href="Styles/jquery-ui-1.8.16.custom.css" rel="stylesheet" type="text/css" />
    <link href="Styles/ui.jqgrid.css" rel="stylesheet" type="text/css" />

    <script src="Scripts/Lib/jquery-1.7.2.min.js" type="text/javascript"></script>

    <script src="Scripts/Lib/jquery.jqGrid.min.js" type="text/javascript"></script>

    <script src="Scripts/Lib/jquery.jqGrid.src.js" type="text/javascript"></script>

    <script src="Scripts/Lib/grid.custom.js" type="text/javascript"></script>

    <script type="text/javascript">
        $(document).ready(function() {

            var lastsel2;
            $("#sample").jqGrid({
                datatype: "local",
                height: 250,
                scroll: false,
                shrinkToFit: false,
                colNames: ['ID Number', 'Name', 'Stock', 'department', 'Notes', 'Service', 'Delivery', 'Result', 'Feedback', 'Total', 'Data', 'Views', 'Rows', 'Columns', 'Table'],
                colModel: [
           { name: 'id', index: 'id', width: 90, sorttype: "int", editable: true, frozen: true },
           { name: 'name', index: 'name', width: 150, editable: true,frozen: true, editoptions: { size: "20", maxlength: "30"} },
           { name: 'stock', index: 'stock', width: 60, editable: true,frozen: true, edittype: "select", editoptions: { value: "aw:Yes;bk:No"} },
           { name: 'dep', index: 'dep', width: 90, editable: true,frozen: true, edittype: "select", editoptions: { value: "a:km;b:bc;c:we;i:gg"} },
           { name: 'note', index: 'note', width: 200, sortable: false, editable: true, edittype: "textarea", editoptions: { rows: "2", cols: "10"} },
           { name: 'Service', index: 'Service', width: 90, sorttype: "int", editable: true },
           { name: 'Delivery', index: 'Delivery', width: 90, sorttype: "int", editable: true },
           { name: 'Result', index: 'Result', width: 90, sorttype: "int", editable: true },
           { name: 'Feedback', index: 'Feedback', width: 90, sorttype: "int", editable: true },
           { name: 'Total', index: 'Total', width: 90, sorttype: "int", editable: true },
           { name: 'Data', index: 'Data', width: 90, sorttype: "int", editable: true },
           { name: 'Views', index: 'Views', width: 90, sorttype: "int", editable: true },
           { name: 'Rows', index: 'Rows', width: 90, sorttype: "int", editable: true},
           { name: 'Columns', index: 'Columns', width: 90, sorttype: "int", editable: true },
           { name: 'Table', index: 'Table', width: 90, sorttype: "int", editable: true }
       ],


                caption: "sample table"
            });
            var mydata2 = [
        { id: "12345", name: "Desktop Computer", note: "note", stock: "Yes", dep: "km", Service: "abc", Delivery: "ccv", Result: "bbc", Feedback: "yes", Total: "100", Data: "rre", Views: "dgx", Rows: "5", Columns: "8", Table: "13" },
        { id: "23456", name: "Laptop", note: "Long text ", stock: "Yes", dep: "bc", Service: "abc", Delivery: "ccv", Result: "bbc", Feedback: "yes", Total: "100", Data: "rre", Views: "dgx", Rows: "5", Columns: "8", Table: "13" },
        { id: "34567", name: "LCD Monitor", note: "note3", stock: "Yes", dep: "we", Service: "abc", Delivery: "ccv", Result: "bbc", Feedback: "yes", Total: "100", Data: "rre", Views: "dgx", Rows: "5", Columns: "8", Table: "13" },
        { id: "45678", name: "Speakers", note: "note", stock: "No", dep: "gg", Service: "abc", Delivery: "ccv", Result: "bbc", Feedback: "yes", Total: "100", Data: "rre", Views: "dgx", Rows: "5", Columns: "8", Table: "13" },
        { id: "56789", name: "Laser Printer", note: "note2", stock: "Yes", dep: "km", Service: "abc", Delivery: "ccv", Result: "bbc", Feedback: "yes", Total: "100", Data: "rre", Views: "dgx", Rows: "5", Columns: "8", Table: "13" },
        { id: "67890", name: "Play Station", note: "note3", stock: "No", dep: "gg", Service: "abc", Delivery: "ccv", Result: "bbc", Feedback: "yes", Total: "100", Data: "rre", Views: "dgx", Rows: "5", Columns: "8", Table: "13" },
        { id: "76543", name: "Mobile Telephone", note: "note", stock: "Yes", dep: "we", Service: "abc", Delivery: "ccv", Result: "bbc", Feedback: "yes", Total: "100", Data: "rre", Views: "dgx", Rows: "5", Columns: "8", Table: "13" },
        { id: "87654", name: "Server", note: "note2", stock: "Yes", dep: "bc", Service: "abc", Delivery: "ccv", Result: "bbc", Feedback: "yes", Total: "100", Data: "rre", Views: "dgx", Rows: "5", Columns: "8", Table: "13" },
        { id: "98765", name: "Matrix Printer", note: "note3", stock: "No", dep: "km", Service: "abc", Delivery: "ccv", Result: "bbc", Feedback: "yes", Total: "100", Data: "rre", Views: "dgx", Rows: "5", Columns: "8", Table: "13" }
        ];

            for (var i = 0; i < mydata2.length; i++) {

                jQuery("#sample").jqGrid('addRowData', mydata2[i].id, mydata2[i]);
            }
        });

        $("#sample").jqGrid('setFrozenColumns');
        $("#sample").trigger('reloadGrid', [{ current: true}]);
       </script>

</head>
<body>
    <form id="form1" runat="server">
    <table id="sample">
    </table>
    </form>
</body>
</html>

这是我的代码。我正在使用 jquery version4.4.0 但是该列仍然没有被冻结。请帮助我解决这个问题。我也尝试过调试代码。方法“setFrozencolumns”被调用,但列没有被冻结

【问题讨论】:

    标签: jquery jqgrid


    【解决方案1】:

    要使用setFrozenColumns,您需要通过在colModel 中设置frozen:true 来标记应冻结哪些列。请在此处阅读更多内容:

    更新

    setFrozenColumns 方法从 jqGrid 4.3.0 版开始可用。您还应该确保您已经检查了 download pageBase 部分中的 Custom 模块(如果您使用的是未压缩分发,则参考 grid.custom.js 文件)。

    【讨论】:

    • 我也试过了.. 但它给了我一个“找不到方法错误”
    • 我也粘贴了编辑后的代码。请检查并帮助我
    • @Xavier 我已经更新了答案,其中包含有关该方法可用位置的一些详细信息。
    • 我已经下载了 v 4.4.0 并在我的代码中添加了以下脚本文件。 错误已解决,但列尚未冻结..请帮帮我
    • @Xavier 您可以在调用 setFrozenColumns 后尝试调用$("#sample").trigger('reloadGrid', [{current:true}]);,但如果您没有打破我给您的链接中描述的任何限制(并且您已验证您是使用正确版本的 jqGrid)比一切都应该正常工作(至少没有什么可以从你描述的内容中诊断出来)。
    【解决方案2】:

    试过了,现在可以正常使用了..

    $("#sample").jqGrid("destroyFrozenColumns")
                .jqGrid("setColProp", "id", { frozen: true })
                .jqGrid("setFrozenColumns")
                .trigger("reloadGrid", [{ current: true}]);
    

    【讨论】:

      猜你喜欢
      • 2011-06-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-07-01
      • 1970-01-01
      • 1970-01-01
      • 2013-10-02
      • 2015-02-21
      相关资源
      最近更新 更多