model-view-controller - jqgrid如何动态创建列

标签 model-view-controller jqgrid

我正在尝试在 mvc 中实现一个 jquery,有几个关于这个的教程,但我不希望 jquery 对列进行硬编码(或者实际上任何要硬编码的东西 - 这是应该的逻辑在 Controller 中。

所以...查看下面的代码,您将看到 colNames: 和 colModel: 我如何编写这些以便我可以循环遍历模型,为每个列项目向网格添加一列?基本上我最终想要的是一个通用的 jqGrid 语句,唯一改变的是 Controller 中的代码!

Query("#list").jqGrid({
    url: '/Home/GetMovieData/',
    datatype: 'json',
    mtype: 'GET',
    colNames: ['id', 'Movie Name', 'Directed By', 'Release Date', 'IMDB Rating', 'Plot', 'ImageURL'],
    colModel: [
        **{ name: 'id', index: 'Id', width: 55, sortable: false, hidden: true },
        { name: 'Movie Name', index: 'Name', width: 250 },
        { name: 'Directed By', index: 'Director', width: 250, align: 'right' },
        { name: 'Release Date', index: 'ReleaseDate', width: 100, align: 'right' },
        { name: 'IMDB Rating', index: 'IMDBUserRating', width: 100, align: 'right' },
        { name: 'Plot', index: 'Plot', width: 55, hidden: true },
        { name: 'ImageURL', index: 'ImageURL', width: 55, hidden: true}],**
    pager: jQuery('#pager'),
    rowNum: 5,
    rowList: [5, 10, 20],
    sortname: 'id',
    sortorder: "desc",
    height: '100%', 
    width: '100%',
    viewrecords: true,
    imgpath: '/Content/jqGridCss/redmond/images',
    caption: 'Movies from 2008'
});

最佳答案

关于model-view-controller - jqgrid如何动态创建列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1684611/

相关文章:

ruby-on-rails - Rails 中随处可见的方法

design-patterns - 游戏设计 MVC - Controller 架构

c# - 向 HTML.DropDownListFor 添加一个类

sorting - jqgrid 日期排序和格式化

java - Intellij Idea Spring 404 – 未找到

javascript - 为什么 AngularJS 在 HTML 中打印双引号

jquery - jqgrid 搜索网格选项

jquery - jqgrid分页不起作用

jquery - 使用jqGrid的emptyrecords选项

jquery - jqgrid 中带有 JSON 数据的树形网格