2

我在 asp.net 项目中使用Sigma 网格。如果数据库返回 null,我想显示没有找到记录。我尝试了一些方法,例如:

var grid = Sigma.$grid(grid_demo_id);
var test1 = grid.dataset.getSize();

但无论是否是记录,它总是返回-1。

我在下面粘贴我的代码:

 var grid_demo_id = "myGrid1";
        var dsOption = {
            fields: [
        { name: 'col1' },
        { name: 'col2' }
        ],
            recordType: 'array'
        }

        var colsOption = [
    { id: 'col1', header: "Col1", width: 105 },
    { id: 'col2', header: "Col2", width: 131 }
];

        var gridOption = {
            id: grid_demo_id,
            loadURL: 'Controller.aspx?P=Location&LocationId=' + globalLocation + '&' +strDate,
            width: "448",
            height: "239",
            container: 'tabcontainer',
            replaceContainer: true,
            encoding: 'UTF-8', // Sigma.$encoding(), 
            dataset: dsOption,
            columns: colsOption,
            clickStartEdit: true,
            defaultRecord: { 'col1': "00", 'col2': ""},
            pageSize: 7,
            pageSizeList: [7, 14, 21],
            toolbarPosition: 'bottom',
            toolbarContent: 'reload | nav | goto | pagesize | print '
        };

        var mygrid = new Sigma.Grid(gridOption);

        Sigma.Util.onLoad(function () { mygrid.render() });

        var grid = Sigma.$grid(grid_demo_id);
        var test1 = grid.dataset.getSize();
        alert(test1);
        if (test1 === -1) {
            alert('In');
            document.getElementById('DivGridView').innerHTML = '<div id=\'divRec\'style=\'float:left;\'>No Record found.</div>';
            document.getElementById('tabcontainer').style.display = "none";
        }
        else {
            document.getElementById('tabcontainer').style.display = "block";
            document.getElementById('DivGridView').style.display = "none";
        }
4

1 回答 1

0

而不是使用 grid.dataset.getSize(),而是使用下面的代码片段来获取网格中存在的数据长度,如果它是 0,您可以打印所需的消息。

//所有数据都存在于 sigma 网格中

var allSelectedRecords = myGrid.dataset.data;

//这将给出sigma网格中存在的行数

allSelectedRecords.length;

于 2016-09-02T08:49:45.687 回答