简体   繁体   English

在Ext JS中获取GridPanel的HTML

[英]Getting HTML of GridPanel in Ext JS

I have a GridPanel which is completely ready and working. 我有一个完全准备好工作的GridPanel。 It is currently rendered to the DOM by calling the render(id) method of Ext.grid.GridPanel . 它通过调用Ext.grid.GridPanelrender(id)方法呈现给DOM。

This results in the GridPanel beeing rendered right before the html element with the given id. 这导致GridPanel在具有给定id的html元素之前呈现。

For programming in my API i now need the rendered HTML of the table in my JavaScript to pass it to another function which can just act on HTML code and i can't change it for compatibility reasons. 对于我的API编程,我现在需要在我的JavaScript中使用表格的呈现HTML将其传递给另一个函数,该函数只能作用于HTML代码,并且出于兼容性原因我无法更改它。 So the render function doesn't return anything and i don't know how to get the html or at least a reference to the DOM-node of the rendered HTML in JavaScript. 因此,渲染函数不返回任何内容,我不知道如何获取html或至少引用JavaScript中呈现的HTML的DOM节点。

any suggestions? 有什么建议么?

You can get the HTML of the DOM node of the body of the grid by doing: 您可以通过执行以下操作获取网格主体的DOM节点的HTML:

gridObject.body.dom.innerHTML

but it is not a table... it is markup styled to look like a table... 但它不是一张桌子......它的标记风格看起来像一张桌子......

The best way to get grid data in HTML would be to add a method to the grid that renders its data into a template. 在HTML中获取网格数据的最佳方法是向网格添加一种方法,将其数据呈现​​为模板。

http://dev.sencha.com/deploy/dev/docs/?class=Ext.XTemplate http://dev.sencha.com/deploy/dev/docs/?class=Ext.XTemplate

Create a dom element, say d. 创建一个dom元素,比方说d。 Then do: Ext.fly(d).replaceWith(yourGrid.getEl()) 然后执行:Ext.fly(d).replaceWith(yourGrid.getEl())

This should replace your created dom element's contents with grid's contents. 这应该用网格的内容替换你创建的dom元素的内容。 This also retains all the state, since ext component is still there. 这也保留了所有的状态,因为ext组件仍然存在。

I dont think you can actually a "String" of the HTML and pass it on to a function. 我不认为你实际上可以是HTML的“字符串”并将其传递给函数。 But you should be able to get reference to the document element, simply by getElementById since you will know the element id (pass it into the config of the GridPanel). 但是您应该能够通过getElementById来获取对document元素的引用,因为您将知道元素id(将其传递给GridPanel的配置)。 You'll simply get reference to the top-level element. 您只需参考顶级元素即可。

Have you seen the kind of HTML generated by ExtJS? 你见过ExtJS生成的那种HTML吗? They are not that nice to work directly with, it's simpler if you work with the GridPanel objects. 它们不是很好直接使用,如果使用GridPanel对象,它会更简单。

Its just not possible to render the table before the element exists AND IS ADDED TO THE DOM in which the grid should be rendered. 它只是不可能在元素存在之前呈现表并且被添加到应该呈现网格的DOM中。 That's really unflexible i think. 我认为这真的不灵活。 But i am forced to use it by the project so i will have to change the API to generate some entrypoint - DIVs for the EXT grid before rendering. 但我被迫在项目中使用它,所以我将不得不更改API以生成一些入口点 -渲染前EXT网格的DIV

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM