【问题标题】:How to get header name (colNames) from data base in jqgrid如何从jqgrid中的数据库中获取标题名称(colNames)
【发布时间】:2015-07-30 19:51:37
【问题描述】:

我有两个加入的表。我从此查询中获取数据并在 jqgrid 中显示。 正常情况下,我的网格是这样的:

我想显示第一列 (C02/ C01 /C01/ C02 /C01),如标题 (colNames) 和第二列 (2.2.2.2 / 1.1.1 /1.1.1 / 8.8.8.8. / 6.6.6.6)对于第一列的值和第二列等其他列的值,位于标题下方。确实,我要将水平网格更改为垂直(我认为)。我的 jqGrid 代码如下:

<script type="text/javascript">
var searchOptions = ['eq', 'ne', 'lt', 'le', 'gt', 'ge', 'bw', 'bn', 'in', 'ni', 'ew', 'en', 'cn', 'nc'];

$(document).ready(function () {
    $('#list').jqGrid({
        caption: "ObisData",
        //url from wich data should be requested
        url: '@Url.Action("GetObisData", "DataGrid")',
        //EditData
        editurl: '@Url.Action("EditData", "DataGrid")',
        //type of data
        datatype: 'json',
        jsonReader: {
            root: "Rows",
            page: "Page",
            total: "Total",
            records: "Records",
            repeatitems: true,
            id: "ObisDataID",
            cell: "RowCells"
        },
        //url access method type
        mtype: 'POST',
        //columns names
        colNames: [ '', '', '', ''],
        //columns model
        colModel: [
            {
                name: 'ObisDataID', index: 'ObisDataID', align: 'right', width: 100,
                editable: false, hidden: true, key: true

            },
        {
            name: 'ObisInfoTitle', index: 'ObisInfoTitle', align: 'center', width: 100,
            editable: false, hidden: false

        }
        ,

        {
            name: 'ObisData', index: 'ObisData', align: 'center', width: 100,
            editable: false, hidden: false
        }
        ,
        {
            name: 'ObisInfoTranslateT', index: 'ObisInfoTranslateT', align: 'center', width: 170,
            editable: false, hidden: false
        }

        ],
        //pager for grid
        pager: $('#pager'),
        //number of rows per page
        rowNum: 10,
        rowList: [10, 20, 50, 100],
        //initial sorting column
        sortname: 'ObisDataID',
        //initial sorting direction
        sortorder: 'desc',
        //we want to display total records count
        viewrecords: true,
        altRows: true,
        shrinkToFit: false,
        width: '1100',
        height: 'auto',
        hidegrid: false,
        direction: "rtl",
        gridview: true,
        rownumbers: true,
        footerrow: true,
        //userDataOnFooter: true,
        loadComplete: function () {
            //change alternate rows color
            $("tr.jqgrow:odd").css("background", "#E0E0E0");
        },
        loadError: function (xhr, st, err) {
            jQuery("#rsperror").html("Type: " + st + "; Response: " + xhr.status + " " + xhr.statusText);
        }
        //, loadonce: true
    })

【问题讨论】:

  • 能不能加jqgrid代码.....
  • @Krishnakumar Subbaiyan 是的。我编辑了我的问题。
  • @KrishnakumarSubbaiyan 是否需要添加控制器?

标签: asp.net-mvc-4 jqgrid jqgrid-asp.net mvcjqgrid


【解决方案1】:

更改方向代码。那么你的网格会从左到右对齐

direction : "ltr"

你不希望行号

rownumbers: false

来自数据库的标题名称

在 jqgrid 代码中添加 colNames 之后,首先在 js 变量中分配 DB 值。

var firstColName={insert DBvalue data};
var secondColName={insert DBvalue data};
var thirdColName={insert DBvalue data};

 colNames: [ firstColName, secondColName,thirdColName, ......],

【讨论】:

  • @Krishnakumr Subbaiyan 我的意思是第一列是标题,另一列是标题的值。我想要垂直网格。在标题中坐 C01 C02 ......并且在标题下方的第一行中坐 2.2.2.2 1.1.1 ,............
  • 但我不知道标头有多少数据。因为我通过连接两个表得到了这个。
  • 感谢您的回复。我在哪里使用 (var firstColName={insert DBvalue data};) DBvalue 是什么?
  • @mahdisdezfouli Jqgrid 您只能将列值用作列值,我对您的问题的看法,您已经修改了后端的值。基于 jqgrid 的列和行。在前端很难做到。
  • @Oleg 很抱歉打扰您。我有个问题。我可以为 jqgrid 使用数据透视属性吗?我想将水平网格更改为垂直。如果可能,请帮助我。非常感谢你
猜你喜欢
  • 2014-03-29
  • 2011-10-30
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-07-22
  • 2018-10-12
  • 2015-11-23
  • 2012-03-06
相关资源
最近更新 更多