cancel
Showing results for 
Search instead for 
Did you mean: 

How to Process table rows in XML view ?

Former Member
0 Kudos

HI All,

I have an Table designed in XML view using mobile library and displays the records from northwind service.

Code:


<Table id="idProductsTable"
inset="false"
items="{/Products}"
visibleRowCount= "7"
mode="MultiSelect"
modeAnimationOn="true">
<headerToolbar>
<Toolbar>
<Label text="Products"></Label>
</Toolbar>
</headerToolbar>

  

<columns>
<Column
width="12em">
<Text text="Product Name" />
</Column>
<Column
minScreenWidth="Tablet"
demandPopin="true">
<Text text="Category ID" />
</Column>
<Column
minScreenWidth="Tablet"
demandPopin="true">
<Text text="Supplier ID" />
</Column>
<Column
minScreenWidth="Tablet"
demandPopin="true">
<Text text="Unit price" />
</Column>
<Column
minScreenWidth="Tablet"
demandPopin="true">
<Text text="Unit in stock" />
</Column>
<Column
minScreenWidth="Tablet"
demandPopin="true">
<Text text="Unit on order" />
</Column>
</columns>
<items>
<ColumnListItem>
<cells>
<Text text="{ProductName}" />
<Text text="{CategoryID}" />
<Text text="{SupplierID}" />
<Text text="{UnitPrice}" />
<Text text="{UnitsInStock}" />
<Text text="{UnitsOnOrder}"/>
</cells>
</ColumnListItem>
</items>

</Table>

Questions:

  • On click of the delete button in the footer How to delete the selected rows just from table. I have very basic idea and its not helping me to proceed further.
  • How to get the selected rows and display the same selected rows in another table?.
  • I have some rows in table and i want to push the complete table content to backend SAP to process it.How to call the url for the same..

       /sap/opu/odata/ZTEST_SRV/entityset(orderno="1234") " this is how i send one order no back to SAP now how to send the table of values?

Please help me out.

I have searched before posting i could not find any reference related to table XML views.

Accepted Solutions (0)

Answers (1)

Answers (1)

Former Member
0 Kudos

Hi Deepan,

implement the below two methods on click of your delete button in your controller.

we have a method getSelectedIndices which returns the selected indices in an array.

https://sapui5.netweaver.ondemand.com/sdk/docs/api/symbols/sap.ui.table.Table.html#getSelectedIndice...

We have a method removeRow which takes your index as input and removes the row.Run a loop so that all the rows can be removed (use  indexe array which is obtained in the step).

https://sapui5.netweaver.ondemand.com/sdk/docs/api/symbols/sap.ui.table.Table.html#removeRow

Cheers

Pandu

Qualiture
Active Contributor
0 Kudos

Please note the 'removeItem()' method only removes the visible row (i.e., the controls) from the aggregation, it does not remove the actual data from your model

I therefor strongly advise not to use the removeRow() and removeItem() methods since they are useless when using data binding

A much better approach is to retrieve the selected contexts from your table, and then remove the corresponding objects from the model:


handleDelete : function(oEvent) {

    var oModel    = this.getView().getModel();

    var aRows     = oModel.getProperty("/rows");   

    var aTable    = oEvent.getSource().getParent().getParent();

    var aContexts = aTable.getSelectedContexts();

    for (var i=aContexts.length -1; i>=0; i--) {

        var oThisObj = aContexts[i].getObject();

        var index = $.map(aRows, function(obj, index) {

            if(obj === oThisObj) {

                return index;

            }

        })

        aRows.splice(index, 1);

    }

    oModel.setProperty("/rows", aRows);

    aTable.removeSelections(true);

},

Please not the above does not take custom sorting and or filtering into account, but you get the idea