Skip to Content
0
May 17, 2020 at 05:55 AM

How to bind the selection column of a smart table to OData Model

1768 Views Last edit May 17, 2020 at 07:20 AM 2 rev

I have added a smart table, it is in mutli select mode. Everything works fine. Except I would like to bind the row selection checkbox to a property in my oData service. Currently if they select some rows, I send which rows they selected to the back end and the odata service updates the records with "checked = true". When they revisit that record I would like to have the selection checkbox bound to a true/false property in my oData model (Similar to the way it works in ALV)

SmartTable in the view

			<smarttable:SmartTable id="smartTable_org_hier" 
			    visible="true" 
			    entitySet="xDSNxC_M_CONT_STRUCTSet"
				class="sapFioriListReportSmartTable" 
				header="Contract Structure" 
				tableType="TreeTable" 
				tableBindingPath="/xDSNxC_M_CONT_STRUCT(p_mod_uuid=guid'{mod_uuid}')/Set"
				beforeRebindTable="onBeforeRebindTable" 
				enableAutoBinding="true" 
				useVariantManagement="false" 
				showVariantManagement="false"
				useTablePersonalisation="true" 
				initiallyVisibleFields="docnumber,description,doctype,checked"
				requestAtLeastFields="docnumber,doctype,ParentDocNumber,NodeId,ParentNodeId,GrandParentNodeId,GrandParentDocNumber,checked">
			</smarttable:SmartTable>

onBeforeRebindTable function (I've been trying to programatically set the checkbox in the _onBindingDataReceivedListener function but I'm not having much success with that either, addSelectedIntervals() doesn't seem to do much in that function. The idea is to loop through the rows, see if the property is true and set the line to selected, but I can't get that to work either.

onBeforeRebindTable: function (oEvent) {
		var oBindingParams = oEvent.getParameter("bindingParams");
		oBindingParams.parameters.threshold = 50000;
		oBindingParams.parameters.countMode = "Inline";
		oBindingParams.parameters.operationMode = "Server";
		oBindingParams.parameters.numberOfExpandedLevels = 1;
		var oFilter = new sap.ui.model.Filter("RootNodeId", sap.ui.model.FilterOperator.EQ, this._oGUID);
		oBindingParams.filters.push(oFilter);
		this.addBindingListener(oBindingParams, "dataReceived", this._onBindingDataReceivedListener.bind(this));

the idea here is if the odata property "checked = true" then those would be checked.

I have also tried to add the below to my smarttable. the idea is to add a new custom column and bind the checkbox field to that. This works except it doesn't render a tree table anymore.

<table:Table>
   <table:columns>
      <table:Column>
         <Label text="Rating"/>
	 <table:customData>
	   <core:CustomData key="p13nData" value='\{"columnKey": "checked", "columnIndex" : "100"}'/>
         </table:customData>
	 <table:template>
	   <CheckBox selected="{checked}" editable="true"></CheckBox>
	 </table:template>
      </table:Column>
   </table:columns>
</table:Table>

Attachments

tableissue.png (10.6 kB)