【问题标题】:MVC3 JQGrid Set colmodel dynamically from controllerMVC3 JQGrid 从控制器动态设置 colmodel
【发布时间】:2012-09-11 22:42:05
【问题描述】:

我已经看到了大量关于在视图中设置 colmodel 的示例,但我无法看到控制器代码! 我正在尝试这样做,但设置一直出错。 我正在尝试达到此列的形成:

colModel:
[
    { name: 'ID', index: 'ID', hidden: true },
    { name: 'Votes', index: 'Votes', width: 100, align: 'left' },
    { name: 'Question', index: 'Question', width: 300, align: 'left' },
    { name: 'my_clickable_checkbox', index: 'my_clickable_checkbox',
        sortable: true,
        formatter: chkFmatter, formatoptions: { disabled: false }, editable: true,
        edittype: "checkbox"
    }
],

这是我在控制器中的试用:

return Json(
    new { colNames = new[] { "ID2", "Votes2", "Question2", "checkbox" },
          colModel = new[] { 
            new { name = "ID", index = "ID", width = 0, formatter="",
                  edittype="", hidden = true },
            new { name = "Votes", index = "Votes", width = 100, formatter="",
                  edittype="", hidden = false },
            new { name = "Question", index = "Question", width = 300, formatter="",
                  edittype="", hidden = false },
            new { name = "checkbox", index = "my_clickable_checkbox", width = 100,
                  formatter="chkFmatter", edittype="checkbox", hidden = false }
          }
}, JsonRequestBehavior.AllowGet);

在控制器中创建这个数组迫使我在所有行中拥有相同数量的属性。例如,我只需要隐藏ID,但它强制我为所有其他列提供hidden 属性。

第二个问题,第四列需要调用js函数chkFmatter

如何在控制器中达到 colModel 格式??

非常感谢。

【问题讨论】:

    标签: asp.net-mvc-3 jqgrid


    【解决方案1】:

    您可能有兴趣查看 jqGrid Importing and exporting 功能。它允许您将整个 jqGrid 配置导入或导出到另一种文件格式。

    你可以阅读这篇博文:

    了解如何将这些功能与 ASP.NET MVC 一起使用的总体思路,但如果涉及 ASP.NET MVC 的东西(它基于 ASP.NET MVC 1),它就有点过时了。

    你也可以看看这个 jqGrid 示例项目:

    其中(除其他外)包含用于配置导入/导出的示例。

    这里要记住的最重要的事情是,您仍然需要在配置导入后设置任何 jqGrid 事件/回调或调用任何其他方法,例如“setFrozenColumns”。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-09-07
      • 2014-03-09
      • 1970-01-01
      • 2015-07-24
      • 1970-01-01
      • 2011-04-21
      • 2014-11-25
      相关资源
      最近更新 更多