Dear community,
I looking for a convenient method to get the path from a table cell.
Background: It is required to implement a search field allowing to filter on all columns of responsive table. Here, the path is needed as parameter for the filter object.
XML Code:
<Table items="{path: 'modelName>pathPart1/pathPart2'}">
<headerToolbar>
<Toolbar>
<Title text="titleText"/>
<SearchField search="searchInTable"/>
</Toolbar>
</headerToolbar>
<columns>
<Column>
<Text text=" column1"/>
</Column>
<Column>
<Text text=" column2"/>
</Column>
</columns>
<items>
<ColumnListItem >
<cells>
<Text text=" {modelName>cellName1}"/>
<Text text="{modelName>cellName2}"/>
</cells>
</ColumnListItem>
</items>
</Table>
Controller logic:
searchInTable: function(event) {
// Access the table
var table = event.getSource().getParent().getParent();
// Search vaule entered by the user
var query = event.getParameters("query");
// Filter on table binding
table.getBinding("items").filter(this.getFilters(table, query));
},
getFilters: function(table, query) {
var aFilters = [];
var items = table.getItems();
// Loop through items aggregation and populate filter object
jQuery.each(items, function(i, oItem) {
// Get path from cells (e.g. cellName1)
var sPath = oItem.mAggregations.cells[i].mBindingInfos.text.binding.sPath;
var sOperator = FilterOperator.EQ;
var sValue1 = query;
var oFilter = new Filter(sPath, sOperator, sValue1);
aFilters.push(oFilter);
});
return aFilters;
}
Can we replace this part by a more convenient and robust method?
var sPath = oItem.mAggregations.cells[i].mBindingInfos.text.binding.sPath;
As you notice I trying to receive the sPath going through the whole object. However, its not working in all cases as the structure of the object may change. I bet there is an better approach available. However, i struggling a bit here. Any ideas?
Thanks!
Edit: I do like to get the path pointing to the text property in the table. In this samplle it would be: cellName2