怎么判断extjs 中gridpanel中是否存在数据

解决方案 »

  1.   

    var count=grid.getStore().getCount()得到数据条数。如果count>0则存在数据,否则,不存在。
      

  2.   

    gridpanel 有个属性叫 emptyText 它可以判断。var grid = new Ext.grid.GridPanel({
        ....
        viewConfig:{
            ....
            emptyText:'No rows to display'
        },
        ....
    });
      

  3.   

    不是这个效果,就是当我gridpanel 在没有可显示的数据就要隐藏,当有数据的就显示,
    var count=grid.getStore().getCount() ,这个也用了,但每次都是count = 0 
      

  4.   

    var grid2 = new Ext.grid.GridPanel({
    id : "grid2",
    renderTo : Ext.getBody()
                    //省略...100行
    }); vstore.load(); if (grid2.getStore().getCount() < 1) {
    alert("隐藏");
    Ext.get("grid2").hide();
    } else {
    alert("显示");
    Ext.get("grid2").show();
    }
      

  5.   

    先给grid设置属性 hidden:true
    然后在store中添加属性:listeners:
    {
        "load":function(store,records,optins)
        {
            var count=records.length;  //等于var count=grid.getStore().getCount() 
            if(count<1)                //count==0
            {
                grid.hide();
            }
            else
            {
                grid.show();
            }
    }
    如果grid.getStore().getCount() 总是等于0的话,你的数据是不是没有传过来?
      

  6.   

    后台是有数据的,只是在选择条件查询的时候可能没数据,但我就希望查询到没数据的时候把这个gridpanel给隐藏起来,如果查询到有数据的时候就显示出来
      

  7.   

    我写在6楼的代码就是你要的功能啊
    监听加载以后的数据,如果有数据则grid显示,如果没有数据则grid隐藏