jquery AppendGrid包含动态数据

时间:2015-03-13 12:57:44

标签: jquery jqgrid

我正在使用jquery appendGrid插件。

  $(function () {
// Initialize appendGrid
$('#myTable').appendGrid({
    caption: 'Manage Field Specifications',
    initRows: 1,
    columns: [
            { name: 'SourceField', display: 'Source Field', type: 'text', ctrlAttr: { maxlength: 5 }, ctrlCss: { width: '90px'} }
        ]
});

myTableData = [             {" SourceField":" SRCFLD1"}];

// Fetch the data to show in the grid;
$('#myTable').appendGrid('load', myTableData);

如果我在" myTableData"中提供硬编码数据,这工作正常。 但是当我从同一页面的隐藏字段/其他内容中获取数据时,网格会出现意外情况。

说,myTableData = document.getElementById(" myHiddenDataForTable")。value;

如果我提供此类数据,表格会出现意外行为,并且会显示添加的大量空行。

协助我获取表的动态数据,并使用提供的dynamicdata正常运行表。

谢谢,

1 个答案:

答案 0 :(得分:0)

$('#myTable').appendGrid({
        caption: 'Manage Field Specifications',
        initRows: 0,
        columns: [
                { name: 'Album', display: 'Album', type: 'text', ctrlAttr: { maxlength: 100 }, ctrlCss: { width: '160px'} },
                { name: 'Artist', display: 'Artist', type: 'text', ctrlAttr: { maxlength: 100 }, ctrlCss: { width: '100px'} },
                { name: 'Year', display: 'Year', type: 'text', ctrlAttr: { maxlength: 4 }, ctrlCss: { width: '40px'} },
                { name: 'Origin', display: 'Origin', type: 'select', ctrlOptions: { 0: '{Choose}', 1: 'Hong Kong', 2: 'Taiwan', 3: 'Japan', 4: 'Korea', 5: 'US', 6: 'Others'} },
                { name: 'Poster', display: 'With Poster?', type: 'checkbox' },
                { name: 'Price', display: 'Price', type: 'text', ctrlAttr: { maxlength: 10 }, ctrlCss: { width: '50px', 'text-align': 'right' }, value: 0 }
            ]
    });



    // Prepare demo data
    var AlbumCount = 0, AlbumData = [];
    for (var z = 0; z < 500; z++) {
        AlbumCount++;
        AlbumData[z] = { 'Album': 'Album ' + AlbumCount, 'Artist': 'Artist ' + AlbumCount, 'Year': 2008 + Math.round(Math.random() * 5), 'Origin': 1 + Math.round(Math.random() * 5), 'Poster': Math.random() > 0.5, 'Price': 100 + Math.round(Math.random() * 1000) / 10 };
    }

    // Load data to grid

    $('#myTable').appendGrid('load', AlbumData);

请使用此示例代码将数据加载到网格中。