为什么使用 gridview:true 是什么意思? [英] Why is gridview:true used for and what does it mean?

查看:34
本文介绍了为什么使用 gridview:true 是什么意思?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在研究 JqGrid.

I am working on JqGrid.

我想知道如果我们指定 gridview:true 是什么意思.

I want to know what does it mean if we specify gridview:true.

在什么情况下我们需要提供?

And in what cases do we need to provide ?

我最近正在研究一个这样的 jqGrid 并且我的 afterInsertRow 没有被调用,一旦我删除了 gridview:true 现在就调用了.

I recently was working on one such jqGrid and my afterInsertRow was not being called, once I remvoed the gridview:true now the call is made.

这是我自己经历过的一个案例,我想知道是否还有其他案例我们应该知道是否使用gridview:true.

This is one case that I myself experienced, I was wondering if there are other cases too which we should know if gridview:true is used.

请指导我.

推荐答案

我同意 gridview: true 选项在文档中没有很好的解释.在某些情况下(例如在 TreeGrid 的情况下),该选项将被自动设置.因此,我尝试解释它的含义以及为什么我建议始终使用 gridview: true 选项而从不使用 afterInsertRow.

I agree that gridview: true option is not good explained in the documentation. In some cases (like in case of TreeGrid) the option will be automatically set. So I try to explain what it mean and why I recommend always to use the gridview: true option and the never use afterInsertRow.

许多人从其他一些计算机语言开始,例如 JavaScript,然后编写了他的第一个程序,这些程序在他们拥有某种程序编写风格后可以在 Web 浏览器中运行.3年前我也遇到过同样的问题.在对 HTML 页面进行一些更改后,了解 Web 浏览器必须执行的操作很重要.在使用 jQuery 时,这是您永久要做的事情.

Many people start with some other computer languages as JavaScript and write his first program which run in web browser after they have some style of writing of programs. I had the same problem 3 year before. It's important to understand what the web browser have to do after you make some changes on the HTML page. In usage of usage of jQuery it's the thing what you permanently do.

如果您更改页面上的某些 DOM 元素,则可以更改页面上所有其他 DOM 元素的位置.如果您考虑浮动模型(例如 float: left)或许多其他 CSS 设置,您就会明白 Web 浏览器不能仅移动现有页面的位图表示并插入新的插入元素.所以Web 浏览器必须重新计算页面上所有元素的位置,并从另一个位置的元素中移动一些.即使您更改元素的 CSS 样式,也会发生如此命名的回流.我建议您阅读文章并观看有关该主题的视频.

If you change some DOM element on the page the position on all other DOM element existing on the page can be changed. If you think about floating model (like with float: left) or many other CSS settings you will understand that web browser can't just move the bitmap representation of the existing page and insert the new inserted element. So the web browser have to recalculate of position all element existing on the page and move some from the elements on another place. Even if you change CSS style of an element the so named reflow take place. I'd recommend you to read the article and to look the video about the subject.

上述情况下提高网络浏览器性能的主要思想是减少页面上的更改次数.因此,您是否需要更改一个 DOM 元素的 5 种样式,您应该在一次操作中完成此操作.您可以将 jQuery.css({...}) 与所有更改的样式一起使用,而不是 5 个单独的调用.更好的是定义一个 CSS 类并使用 jQuery.addClass 方法.

The main idea to improve performance of web browser the the described above case will be to reduce the number of changes on the page. So is you need to change 5 styles of one DOM elements you should do this in one operation. You can use jQuery.css({...}) with all the changed styles instead of 5 separate calls. Even better could be to define one CSS class and use jQuery.addClass method.

在 jqGrid 的情况下,需要用网格的所有行和单元格填充 .如果您使用 gridview: true 选项,则 jqGrid 将所有行的内容收集为带有 HTML 片段的字符串.后来 jqGrid 调用 jQuery.append该行 在内部设置innerHTML 属性以设置页面上的整个HTML 片段.

In case of jqGrid one need to fill <tbody> with all rows and cells of the grid. If you use gridview: true option then jqGrid collect the content of all rows as strings with HTML fragments. Later jqGrid call jQuery.append in the line which set internally innerHTML property to set the whole HTML fragment on the page.

出于同样的原因,您应该使用 cellattrrowattr自定义格式化程序 与 HTML 片段一起使用,将单元格或行表示为字符串.最后,这些字符串将被附加到其他字符串,并将用于 jQuery.append 操作,就像我上面描述的那样.

Because of the same reason you should use cellattr, rowattr or custom formatters which works with HTML fragments represented the cells or rows as strings. At the end the strings will be appended to other strings and will be used in jQuery.append operation like I described above.

afterInsertRow回调函数的使用要求在调用afterInsertRow回调之前,网格的每一行都将放置在页面上.因此无法使用 gridview: true 选项并导致页面运行缓慢.

The usage of afterInsertRow callback function require that every row of the grid will be placed on the page before calling of afterInsertRow callback. So it makes impossible the usage of gridview: true option and make working of the page slowly.

确切地说,我应该提到我之前描述的性能下降只有在大网格的情况下才能看到,并且在慢速 Web 浏览器(如 Internet Explorer,尤其是旧版本的 IE)的情况下会很明显.

To be exact I should mention that the performance decreasing which I described before could be visible only in case of large grid and will be mostly clear seen in case of slow web browser (like Internet Explorer, especially old versions of IE).

这篇关于为什么使用 gridview:true 是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆