简体   繁体   English

如何在extjs小部件列中获取rowIndex

[英]How to get rowIndex in extjs widget column

I need a button in a widget column to know its rowIndex in an ExtJS 6 panel.grid, so that on button click it can use that functionality. 我需要一个小部件列中的按钮来知道它在ExtJS 6 panel.grid中的rowIndex,以便在按钮上单击它可以使用该功能。 I know I can pull that information from the renderer function, but that seems to execute before the button has been created. 我知道我可以从渲染器函数中提取该信息,但这似乎在创建按钮之前就已执行。 Any ideas on how I can get the index? 关于如何获取索引的任何想法?

Use indexOf on the gridview . gridview上使用indexOf You need to pass it the node as argument, which is the HTML element representing the row. 您需要将node作为参数传递给它,这是表示行的HTML元素。 In Ext JS 6, grid rows are HTML tables, so the button's row element can be found from the button element b as b.el.up('table') . 在Ext JS 6中,网格行是HTML表,因此可以从按钮元素bb.el.up('table')形式找到按钮的row元素。 The gridview can also be found as b.up('gridview') . gridview也可以作为b.up('gridview') So you get: 这样就得到:

var rowIndex = b.up('gridview').indexOf(b.el.up('table'));

See in action: https://fiddle.sencha.com/#fiddle/snq 实际操作中查看: https//fiddle.sencha.com/#fiddle/snq

Building on Drake's answer, I'm using the event.record property instead. 基于Drake的答案,我改用event.record属性。 Unfortunately, it looks like you have to make the click event have a slight buffer, so it gets the proper record added to it. 不幸的是,您似乎必须使click事件具有轻微的缓冲,因此它会添加适当的记录。 This works, but I'm not entirely sure if it's a proper way. 这可行,但是我不确定这是否是正确的方法。 Example : 范例

{
  width: 150,
  xtype: 'widgetcolumn',
  widget: {
    text: 'Button',
    xtype: 'button',
    text: 'Get row index',
    listeners: {
      buffer: 1,
      click: function(button, event, eOpts) {
        var record = event.record;
        alert(store.find('postid', record.get('postid'), 0, false, true, true))
      }
    }
  }
}

Use the onWidgetAttach 使用onWidgetAttach

A function that will be called when a widget is attached to a record. 将小部件附加到记录时将调用的函数。 This may be useful for doing any post-processing. 这对于进行任何后处理可能很有用。

http://docs.sencha.com/extjs/5.1.2/api/Ext.grid.column.Widget.html#cfg-onWidgetAttach http://docs.sencha.com/extjs/5.1.2/api/Ext.grid.column.Widget.html#cfg-onWidgetAttach

The function has both widget and record parameter. 该函数同时具有小部件和记录参数。 You can do widget.record = record, and then the button will have the record member which you can access in the click listener 您可以执行widget.record = record,然后按钮将具有记录成员,您可以在单击侦听器中访问该成员。

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

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