Jqgrid'setLabel'不起作用

时间:2013-03-07 07:38:56

标签: jquery jqgrid

我刚尝试使用setLabel更改jqgrid中的列名。但它不起作用。文档说:

  

方法: setLabel

     

参数:   colname的,   数据,   类,   特性

     

返回: jqGrid对象

     

说明:   在指定列的标题中设置新标签;还可以设置属性和类。参数是:   colname列的名称(此参数可以是从0开始的数字(列的索引)   数据可以放入标签的内容。如果为空字符串,则不会更改内容   class如果class是string,那么我们使用addClass向标签添加一个类;如果class是一个数组,我们通过css设置新的css属性   属性设置标签

的属性

小提琴:http://jsfiddle.net/m6DQk/

HTML

<table id="list"></table>
<div id="pager"></div>

JS (请注意此处的最后3条陈述)

$(document).ready(function(){
$("#list").jqGrid({
    datatype: "local",
    height: 250,
    colNames: ['Inv No', 'Date', 'Client', 'Amount', 'Tax', 'Total', 'Notes'],
    colModel: [{
        name: 'id',
        index: 'id',
        width: 60,
        sorttype: "int"
    }, {
        name: 'invdate',
        index: 'invdate',
        width: 90,
        sorttype: "date"
    }, {
        name: 'name',
        index: 'name',
        width: 100
    }, {
        name: 'amount',
        index: 'amount',
        width: 80,
        align: "right",
        sorttype: "float"
    }, {
        name: 'tax',
        index: 'tax',
        width: 80,
        align: "right",
        sorttype: "float"
    }, {
        name: 'total',
        index: 'total',
        width: 80,
        align: "right",
        sorttype: "float"
    }, {
        name: 'note',
        index: 'note',
        width: 150,
        sortable: false
    }],
    multiselect: true,
    caption: "Manipulating Array Data"
});
var mydata = [{
    id: "1",
    invdate: "2007-10-01",
    name: "test",
    note: "note",
    amount: "200.00",
    tax: "10.00",
    total: "210.00"
}, {
    id: "2",
    invdate: "2007-10-02",
    name: "test2",
    note: "note2",
    amount: "300.00",
    tax: "20.00",
    total: "320.00"
}, {
    id: "3",
    invdate: "2007-09-01",
    name: "test3",
    note: "note3",
    amount: "400.00",
    tax: "30.00",
    total: "430.00"
}, {
    id: "4",
    invdate: "2007-10-04",
    name: "test",
    note: "note",
    amount: "200.00",
    tax: "10.00",
    total: "210.00"
}, {
    id: "5",
    invdate: "2007-10-05",
    name: "test2",
    note: "note2",
    amount: "300.00",
    tax: "20.00",
    total: "320.00"
}, {
    id: "6",
    invdate: "2007-09-06",
    name: "test3",
    note: "note3",
    amount: "400.00",
    tax: "30.00",
    total: "430.00"
}, {
    id: "7",
    invdate: "2007-10-04",
    name: "test",
    note: "note",
    amount: "200.00",
    tax: "10.00",
    total: "210.00"
}, {
    id: "8",
    invdate: "2007-10-03",
    name: "test2",
    note: "note2",
    amount: "300.00",
    tax: "20.00",
    total: "320.00"
}, {
    id: "9",
    invdate: "2007-09-01",
    name: "test3",
    note: "note3",
    amount: "400.00",
    tax: "30.00",
    total: "430.00"
}];
    for (var i = 0; i <= mydata.length; i++){
        $("#list").jqGrid('addRowData', i + 1, mydata[i]);
    }

    $("#list").jqGrid('setLabel', 1,"aa");
    $("#list").jqGrid('setLabel', 2,"bb");
    $("#list").jqGrid('setLabel', 3,"cc");

    });

2 个答案:

答案 0 :(得分:3)

变化:

$("#list").jqGrid('setLabel', 1,"aa");
$("#list").jqGrid('setLabel', 2,"bb");
$("#list").jqGrid('setLabel', 3,"cc");

$("#list").jqGrid('setLabel', "id","aa"); //colModel name value
$("#list").jqGrid('setLabel', "invdate","bb");
$("#list").jqGrid('setLabel', "name","cc");

答案 1 :(得分:1)

您应该只使用列名而不是列位作为setLabel的参数。

查看更新的代码http://jsfiddle.net/m6DQk/1/