cancel
Showing results for 
Search instead for 
Did you mean: 

How to bind the EntitySet via Controller to Table by applying multiple Filters?

Jayakrishnan
Active Participant
0 Kudos

Hi All,

I am working on custom sapui5 application development. i need to bind the two different entityset with ui table based on the selection from the combo box. example if i choose Order/Notification from combo box i need to bind OrderSet/NotificationSet with table respectively. These two OrderSet and NotificationSet requires filters to restrict the data.

I have used the following code to bind it. but it throws duplicate id error. but i dont have any duplicate id in my code.

	var fltr_NotificationType = new sap.ui.model.Filter("Qmart", sap.ui.model.FilterOperator.EQ, "M1");
				var fltr_TechnicalPlatz = new sap.ui.model.Filter("TPLNR", sap.ui.model.FilterOperator.EQ, "RR-R77-4-M/R");
				var fltr_StartDate1 = new sap.ui.model.Filter("FromDate", sap.ui.model.FilterOperator.EQ, "(Datetime'2012-10-25T00:00:00')");
				var fltr_EndDate1 = new sap.ui.model.Filter("ToDate", sap.ui.model.FilterOperator.EQ, "(Datetime'2018-10-25T00:00:00')");
		


				oTable.setHeaderText("Notofication List");


				var notificationTableColumn1 = new sap.m.Column("id_table_notification_column_1", {
					header: new sap.m.Label({
						text: "Qmnum"
					})
				});
				oTable.addColumn(notificationTableColumn1);


				var notificationTableColumn2 = new sap.m.Column("id_table_notification_column_2", {
					header: new sap.m.Label({
						text: "Qmart"
					})
				});
				oTable.addColumn(notificationTableColumn2);


				var notificationColumnList = new sap.m.ColumnListItem("id_columnlist_notification", {
					type: "Active"


				});
				var tableNotificationCell1 = new sap.m.Text("id_table_notification_cell1", {
					text: "{Qmnum}"
				});
				notificationColumnList.addCell(tableNotificationCell1);


				var tableNotificationCell2 = new sap.m.Text("id_table_notification_cell2", {
					text: "{Qmart}"
				});
				notificationColumnList.addCell(tableNotificationCell2);


				oTable.bindAggregation("items", {
					path: "/NotificationsSet",
					template: notificationColumnList,
					filters: [fltr_NotificationType, fltr_TechnicalPlatz, fltr_StartDate1, fltr_EndDate1]
				});
			}



While do inspecting,

i am getting this error.

adding element with duplicate id 'id_table_notification_column_1'


Please help me to sort out his issue.

Thank you,

Regards,

JK.


Accepted Solutions (0)

Answers (1)

Answers (1)

maheshpalavalli
Active Contributor
0 Kudos

I hope you are not calling that code repeatedly, which will obviously results in duplicate error. If at all you want to call the code multiple times, persist the table reference as this.oTable = table(which you have defined) and persist the template as well. Then next time when you call it remove the aggregation and add it again withe the persisted template and new filters.. If this answers doesnt clarifies your question, provide proper steps of your scenario.

Jayakrishnan
Active Participant
0 Kudos

Thanks Mahesh for the response,

Yes. I guess, without knowingly somewhere it is getting called repeatedly.

This is my scenario:

I have one dropdown. it cointains two items (Order and Notification).

when i select order, i need to call the below EntitySet with filters and displays in table.

/OrderSet?$filter=TPLNR eq '123' and Auart eq 'PM01' and FromDate eq (Datetime'2012-10-25T00:00:00') and ToDate eq (Datetime'2018-10-25T00:00:00')

when i select notification, i need to call the below EntitySet with filters and displays in table.

NotificationsSet?$filter=Qmart eq 'M1' and TPLNR eq '123' and FromDate eq (Datetime'2012-10-25T00:00:00') and ToDate eq (Datetime'2018-10-25T00:00:00')

In my xml view i just created tabl;e and id only.

	<Table id="id_Table"></Table>

Hope you got it.

Thank you

Jayakrishnan
Active Participant
0 Kudos

It is working after i modified date format which used in the filter value. But I dont know how to un bind the values with table based on drop down selection

Jayakrishnan
Active Participant
0 Kudos

How to use this.OTable=Table, please provide if you have any sample.

Jayakrishnan
Active Participant
0 Kudos

by removing the id and clearing the table column i am able to see it. it is working.

maheshpalavalli
Active Contributor
0 Kudos

Yah that is a way, you can remove the id and do it, but it will create a new table every time you change the type. Best way is to persist it.

You can do it in two ways.

1. If your entities are having similar fields, make it a single entry and show only one table instead of two table by passing filter to the same table again and again based on the selection.

2. If two entities are required, create two table separately and persist them and remove them from the page content dynamically based on the selection(status 1, you will show table 1, status 2 you will show table2).

for this, it is better to create 2 fragments, which will have 2 different tables with their own entitysets, later on instatiate the fragments based on the type of selection. Remember to not create the fragments multiple time, persist them in the controller.