cancel
Showing results for 
Search instead for 
Did you mean: 

SAP MDK best select all/ multi select solutions for object table

dhanikawick41
Participant
0 Kudos

Hi Expert,

I have a requirement to implement select all and multi select functionalities to a object table.

I saw the below links which were very helpful.

MDK Multi select Confirm

How to implement Checkmark and multiple selection using MDK?

From the above suggestions I implemented something as below.

Solution 1 - If the user clicks on the item, I am updating a property in the EntitySet which causes the table to redraw as I have used that EntitySet in DataSubcriptions. Based on the updated property, I am showing an image to display that as selected.

Solution 2 - Then I have a select all action button. If the user clicks on it, I loop through all the items in the table and update the same property in the EntitySet which again shows the image as selected for all lines when the redraw happens. For this, I chain the executeAction to call the UpdateEntity using promises. But this select all functionality is very slow and has visible performance issues.

function ExecuteUpdateEntity(pageProxy, binding) {
	pageProxy.setActionBinding(binding);
	return pageProxy.executeAction('/SAPAssetManager/Actions/SmartInspection/TechnicalObjectSave_UpdateEntity.action');
}


function Wait() {
	return new Promise(r => setTimeout(r, 1000))
}


export default function TechnicalObjectPermSaveList_SelectAll(clientAPI) {
	let pageProxy = clientAPI.getPageProxy();
	let myListPageClientData = '';
	var latestPromise = Promise.resolve();


	try {
		myListPageClientData = clientAPI.evaluateTargetPath("#Page:TechnicalObjectPermSaveList/#ClientData");
	} catch (err) {}


	for (var i = 0; i < myListPageClientData.UnselectedBindingObjects.length; i++) {
		let binding = myListPageClientData.UnselectedBindingObjects[i];
		if (binding.SaveMode !== 'Save') {
			latestPromise = latestPromise.then(() => {
				binding.SelectedToSave = 'X';
				return ExecuteUpdateEntity(pageProxy, binding);
			}).then(Wait);
		}
	}


	return latestPromise.then(function () {}.bind(pageProxy));
}

Although solution 1 seems fine, solution 2 is not acceptable at all.

Am I doing this correctly? Or is there a better way to do it? For me, trying to update a property in the EntitySet by chaining and redrawing seems to be a performance hit. How can I overcome this?

Thank you.

Accepted Solutions (1)

Accepted Solutions (1)

bill_froelich
Product and Topic Expert
Product and Topic Expert

For tracking what items are selected you could track it in memory rather than updating a property on the entity. Of course it depends on your requirements. For my use case, I wanted to select multiple items and then perform some action against each item selected. The next time I came back to the list I wanted it reset back so in memory tracking (via an array in page client data) was a better solution for me.

For Select All, that of course has performance implications since the list when loaded will only show the first 50 items. The total count for the list might be much larger (hundreds or thousands or more) and looping over them one at a time may have a noticeable delay. Again, depending on your requirement if you are selecting everything and then kicking off a process against each one you might just be able to have a button to process all without visually selecting them all first. If you are tracking in memory you might be able to "flip" your logic into an exclude rather than include so that you don't have to loop over each one first to display the selected image.

dhanikawick41
Participant
0 Kudos

Hi bill.froelich

Thank you for your reply.

Yes, for single selection, having it in client data make sense as a better option. Like you said, the reason I went with the entity update option is because, I need to show the selections the next time user comes to the screen.

For the select all option, I went with your suggestion and did not show the selection for all the entries. I did not foresee all the issues you have mentioned in the reply. So it really makes sense to go ahead with what you suggested.

Thank you very much.

Answers (0)