【问题标题】:Overriding JQGrid params defind in server side覆盖在服务器端定义的 JQGrid 参数
【发布时间】:2012-06-25 09:36:15
【问题描述】:

我正在处理使用 C# 在服务器端通过 JQGrid 生成的表的 CSS。我试图覆盖客户端的布局定义(例如宽度)(当然是在代码中生成服务器端表之后),但什么也没得到。唯一有效的方法是创建一个全新的 jqgrid 对象,这显然会使所有服务器端定义无效,因此没有用。

有没有办法以某种方式在客户端重新生成对象的 JavaScript 副本,然后对其应用更改?

非常欢迎您的帮助。

编辑: 这是用于使用 C# 生成表的代码:

        this.projectGrid = new JQGrid
        {
            Columns = new List<JQGridColumn>()
            {
                new JQGridColumn { Visible=true,
                                   Editable=false,
                                 //  Width=70,
                                   DataField="compliance_colour",
                                   HeaderText="Comp.",
                                   Searchable=false,
                                    Formatter = new CustomFormatter
                                                             {
                                                              FormatFunction = "formatCmpImage"

                                                             }


                },
                new JQGridColumn{ DataField="ProjectID",
                                  PrimaryKey=true,
                                  Visible=true,
                                  Editable=false,
                                  HeaderText="ID",
                                //  Width=50,
                                  Searchable=false
                },
                new JQGridColumn{ DataField="OpsRegion",
                                  Visible=true,
                                  Editable=false,
                                  HeaderText="Ops Region",
                               //   Width=180,
                                  Searchable=false

                },
                  new JQGridColumn{DataField="customer",
                                 Visible=true,
                                 Editable=false,
                                 HeaderText="Customer Name",
                               //  Width=180,
                                 Searchable=false

                },
                  new JQGridColumn{ DataField="projectName",
                                  Visible=true,
                                  Editable=false,
                                  HeaderText="Project Name",
                                //  Width=300,
                                  Searchable=false,
                                  Formatter = new CustomFormatter
                                                             {
                                                              FormatFunction = "formatLink",

                                                             }


                },

                new JQGridColumn{DataField="projectManager",
                                 Visible=true,
                                 Editable=false,
                                 HeaderText="Project Manager",
                              //   Width=110,
                                    Searchable=false
                },
                new JQGridColumn{DataField="status",
                                 Visible=true,
                                 Editable=false,
                                 HeaderText="Status",
                              //   Width=70,
                                 Searchable=false

                },
                new JQGridColumn {DataField="type",
                                  Visible=true,
                                  Editable=false,
                                  HeaderText="Type",
                             //     Width=70,
                                  Searchable=false

                },
                new JQGridColumn {DataField="favorite",
                                  Visible=true,
                                  Editable=false,
                                  HeaderText="Favorite",
                              //    Width=60,
                                  Searchable=false,
                                  Formatter = new CustomFormatter
                                                                {
                                                                    FormatFunction = "formatFvImage",
                                                                    UnFormatFunction = "unformatCell"
                                                                }

                },
                 new JQGridColumn {DataField="compliance_reason",
                                  Visible=false      
                },
                 new JQGridColumn {DataField="lastUpdate",
                                  Visible=true,
                                  Editable=false,
                               //   Width=60,
                                  HeaderText="Last Update",
                                  Searchable=false,
                                  Formatter = new CustomFormatter
                                                                {
                                                                    FormatFunction = "formatReportLink",
                                                                    UnFormatFunction = "unformatCell"
                                                                }

                },
            },
           Width = Unit.Pixel(1400),
            ShrinkToFit=true,
            Height = Unit.Pixel(520),

        };

【问题讨论】:

  • 您是否使用来自trirand.com免费 开源jqGrid 或一些基于jqGrid 的商业 产品,例如来自trirand.net 的jqSuite?在最后一种情况下,您应该使用问题的另一个标签,例如jqgrid-asp.net

标签: c# javascript jquery-plugins jqgrid


【解决方案1】:

如果您需要更改网格的width,您可以使用setGridWidth 方法。要覆盖许多其他 jqGrid 选项,您可以改用 setGridParam。您可以在创建网格之后使用方法。一般来说,如果有人存在确切的选项,你应该使用 jqGrid methods(比如setCaptionsetGridHeightsetColProp,...)。如果您发现没有特殊的 jqGrid 方法来更改选项,您可能应该使用setGridParam 方法。

【讨论】:

  • 感谢您的回答。但是,我显然尝试过这个 b4 发布我的问题。恕我直言,问题在于表是在服务器端生成的,因此必须首先获取该表obj的JS副本,b4试图操纵任何参数
  • @Matanya:您没有描述如何(以何种方式)“生成”表格(???是网格还是您使用tableToGrid?)。您应该发布更多详细信息。您如何尝试更改 jqGrid 的选项?您是在创建网格之后 做的吗(请参阅我的回答)?如果您的 JavaScript 代码将在 创建网格之前调用,您可以更改页面上 jqGrid 的 default 选项 ($.extend($.jgrid.defaults, {...});)。例如,请参阅here
  • @Matanya:您在问题的 edit 部分中发布的代码表明您使用 commercial 产品,例如来自trirand.net 的 jqSuite的jqGrid。我只能重复我上次评论中的建议。您可以在the answer 的更新部分中找到这种方法的示例(答案不被接受,但我测试了我之前发布的代码并且它有效)。取决于您在 ASPX 页面上包含 &lt;asp:Content&gt;... 的位置,您可以减少代码。
猜你喜欢
  • 2014-11-14
  • 2017-02-19
  • 1970-01-01
  • 1970-01-01
  • 2015-07-27
  • 2020-04-28
  • 1970-01-01
  • 1970-01-01
  • 2011-03-14
相关资源
最近更新 更多