简体   繁体   English

如何在单击表格时获取特定行的单元格的 position

[英]how to get position of a cell of a particular row on clicked of a table

A basic question, but stuck on how to,一个基本的问题,但坚持如何,

I have a table like below:我有一个如下表:

col0  col1  col2  col3  col3  col5
row1 | A  |   B |   C |  D  |  E
row2 | X  |   Y |   Z |  S  |  T

I am looking for a solution like if I click on A how to get the value of its position as 1 , if B 2 similarly X 1 ....?我正在寻找一种解决方案,例如如果单击A如何获取其 position 的值为1 ,如果B 2类似X 1 ....?

I was doing it like below:{tried with different scenario}我是这样做的:{尝试不同的场景}

new sap.ui.core.Icon({

            press : function(evt) {

                   var source=evt.getSource();

                      var iconIndex=evt.mParameters.id; 
                      var iconIndexValue=iconIndex.split('-'); #{iconIndex = "__icon13-container-........}
                      var indexnumber=iconIndexValue[0].substring(6);#{13}
                        .......}
              ....

The issue I am facing using above method is when page on loaded, if I select A the value I get is 6 which is next set of position values, but when I refresh the page It is again 1 .我使用上述方法面临的问题是加载页面时,如果我 select A我得到的值为6 ,这是下一组 position 值,但是当我刷新页面时它又是1

Is there any different approach to get as above?有什么不同的方法可以得到上述吗?

I am also stuck on how to explain this in breif, but I guess the above expected result makes sense..我也被困在如何用 breif 解释这一点,但我想上述预期结果是有道理的。

Any help is appreciated!!任何帮助表示赞赏!

As per my understanding you need to know the clicked cell position.根据我的理解,您需要知道点击的单元格 position。 You can achieve it by table methods like indexOfItem() and indexOfCell()您可以通过indexOfItem()indexOfCell()等表格方法来实现它

View.xml查看.xml

<Table items="{/items}">
    <columns>
        <Column> <Text text="Amount" /> </Column>
        <Column> <Text text="Quantity" /> </Column>
        <Column> <Text text="Weight" /> </Column>
        <Column> <Text text="Status" /> </Column>
    </columns>
    <items>
        <ColumnListItem>
            <cells>
                <Link text="{Amount}" press="getCellInfo" />
                <Link text="{Quantity}" press="getCellInfo" />
                <Link text="{Unit}" press="getCellInfo" />
                <Link text="{parameter1}" press="getCellInfo" />                    
            </cells>
        </ColumnListItem>
    </items>
</Table> 

Controller.js Controller.js

getCellInfo: function(oEvent) {
    var oCell = oEvent.getSource();
    var oRow = oCell.getParent();
    var oTable = oRow.getParent();
    console.log("Row: "  + oTable.indexOfItem(oRow) + " Cell index: ", oRow.indexOfCell(oCell));        
},

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

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