How to know row number when typing in input field in table

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP



How to know row number when typing in input field in table



In my XML view, I have a Table, in that Table I have Input field at a particular column, and I have a function for liveChange event of that Input field. Code is like below:


<Table ...>
<columns> ... </columns>
<items>
<ColumnListItem>
<cells>
......
<Input type ="Number" value="..." liveChange="qtyChanged"/>
</cells>
</ColumnListItem>
</items>
</Table>



In qtyChanged(), I need to know the row number on which user is editing. How to achieve it?


qtyChanged()





Use the getParent() and reach the row and the row index.
– inizio
Aug 6 at 7:37


getParent()




2 Answers
2



You can achieve it using indexOfItem() of sap.m.Table


indexOfItem()


sap.m.Table


qtyChanged: function(oEvent)
var oRow = oEvent.getSource().getParent();//Get Row
var oTable = oRow.getParent();// Get Table
var iRowIndex = oTable.indexOfItem(oRow);//Get Row index



Note: If the response data is more then table row limit then scroll will appear, then the row index will not work properly.


table row limit



you can get the binding context and then the path. you're also able to get the object itself like this (working example http://jsbin.com/hutuvo/edit?html,output)


<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta charset="UTF-8">
<title>MVC</title>
<script id="sap-ui-bootstrap" type="text/javascript"
src="https://sapui5.hana.ondemand.com/resources/sap-ui-core.js"
data-sap-ui-theme="sap_bluecrystal"
data-sap-ui-libs="sap.m,sap.ui.table"
data-sap-ui-xx-bindingSyntax="complex">
</script>

<script id="oView" type="sapui5/xmlview">
<mvc:View
controllerName="sap.example.Controller"
xmlns:core="sap.ui.core"
xmlns:mvc="sap.ui.core.mvc"
xmlns="sap.m"
height="100%">
<Table id="idProductsTable" items=" path: 'suppliers>/suppliers'">
<columns>
<Column><Text text="Supplier" /></Column>
<Column><Text text="Quantity" /></Column>
</columns>
<items>
<ColumnListItem>
<cells><Text text="suppliers>SupplierName" /></cells>
<cells><Input type ="Number" value="suppliers>Quantity" liveChange="qtyChanged" /></cells>
</ColumnListItem>
</items>
</Table>
</mvc:View>
</script>
<script>
sap.ui.define([ "sap/ui/core/mvc/Controller", "sap/ui/model/json/JSONModel"],
function(Controller, JSONModel)
"use strict";

var oPageController = Controller.extend("sap.example.Controller",
onInit: function()
var oView = this.getView();
oView.setModel(new JSONModel(
suppliers: [

SupplierName: "Apple",
Product: "iPhone",
Quantity: 0
,
SupplierName: "Samsung",
Product: "Galaxy",
Quantity: 0

]
), "suppliers");
,
qtyChanged: function(oEvent)
var oContext = oEvent.getSource().getBindingContext("suppliers");
var oPath = oContext.getPath();
var index = parseInt(oPath.substring(oPath.lastIndexOf("/") + 1), 10);
console.log(index);
console.log(oContext.getObject());

);
return oPageController;
);

var oView = sap.ui.xmlview(
viewContent: jQuery('#oView').html()
);

oView.placeAt('content');
</script>
</head>

<body class="sapUiBody" role="application">
<div id="content"></div>
</body>
</html>





Disagree. A regular OData will have paths whose final part represents the ID of the bound object, not its order in the aggregation. Moreover, he is asking for the row, which is very different from the index of the object in the entity set if the table is scrolled.
– Florian
Aug 6 at 7:24






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

Firebase Auth - with Email and Password - Check user already registered

Dynamically update html content plain JS

Creating a leaderboard in HTML/JS