javascript 有没有办法测试 jqGrid 是否有数据?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9685823/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-26 07:27:18  来源:igfitidea点击:

Is there a way to test if jqGrid has data or not?

javascriptjqueryjqgrid

提问by pundit

I'm trying to enable and disable custom buttons on a jqgrid, but would enable that button only if the grid is empty and then disable when its not.

我正在尝试启用和禁用 jqgrid 上的自定义按钮,但仅当网格为空时才启用该按钮,然后在它不是时禁用。

Is there a way to test of the grid has data or not?

有没有办法测试网格有没有数据?

Thanks.

谢谢。

回答by Justin Ethier

You can test to see how many records are in the grid. If there are no rows then the grid is empty:

您可以测试以查看网格中有多少记录。如果没有行,则网格为空:

jQuery('#grid').jqGrid('getGridParam', 'reccount');

See the documentation for reccount:

请参阅reccount的文档:

Readonly property. Determines the exactly number of rows in the grid.

只读属性。确定网格中的确切行数。

Also, since the default value is 0you need to make sure you call this function after data has loaded, such as in the loadCompleteevent.

此外,由于默认值是0您需要确保在数据加载后调用此函数,例如在loadComplete事件中。

回答by epascarello

From the docs:

文档

reccountinteger Readonly property.

reccount integer 只读属性

Determines the exactly number of rows in the grid. Do not mix this with records parameter. Instead that in most cases they are equal there is a case where this is not true. By example you define rowNum parameter 15, but you return from server records parameter = 20, then the records parameter will be 20, the reccount parameter will be 15, and in the grid you will have 15 records.

确定网格中的确切行数。不要将其与记录参数混合使用。相反,在大多数情况下它们是相等的,但在某些情况下并非如此。例如,您定义 rowNum 参数为 15,但您从服务器记录参数 = 20 返回,则记录参数将为 20,记录参数将为 15,并且在网格中您将有 15 条记录。

回答by DisplayName

In the loadcomplete event you have access to the data object that was bound to the grid and you can check the number of records. There you will also be able to setup your buttons

在 loadcomplete 事件中,您可以访问绑定到网格的数据对象,并且可以检查记录数。在那里你还可以设置你的按钮

loadComplete: function(data){ 
    //data.Rows.length or call reccount
   },