Removing Duplicates From ListGrid

Hi,

How do you prevent duplicate records from being added to a listgrid?

Thanks,

Newt

If you mean via drag and drop, you can override recordDrop() on the target ListGrid, check for dups using listGrid.data.find() and similar APIs, and refuse to call Super() if you don’t want to proceed with the drop (perhaps also using isc.say() to notify the user).

Overriding recordDrop()

Thanks for that information. What is the expected function parameters when I redefine the recordDrop() function?

Thanks again.

Newt

Remember you can always search the reference:

http://www.smartclient.com/docs/6.5.1/a/b/c/go.html?search=recorddrop

Hi,

I got it to work but when I attempt to drag the same data over the first time but if I drag over the data with the same data selected, it seems to add the records I excluded from the last time.

Here is the code:

recordDrop: function (dropRecords, targetRecord, index, sourceWidget) {
var employeesNotAddedMessage = ‘’;
for (i=0; i < dropRecords.length; i++) {
if (currentTeamMembersList.data.find(“employeeid”, dropRecords.get(i).employeeid)) {
employeesNotAddedMessage = employeesNotAddedMessage + dropRecords.get(i).fullname + " (" + dropRecords.get(i).employeeid + “) is already a member of the team.” + “<br>”;

		        			dropRecords.removeAt(i);
		        		}
		        	}
		        	var newDropRecords = dropRecords;
		        	if (newDropRecords.length &gt; 0) {
		        		for (j=0; j &lt; newDropRecords.length; j++) {
		        			this.Super("recordDrop", newDropRecords.get(j), targetRecord, index, sourceWidget);
		        		}
		        	}
		        	isc.say(employeesNotAddedMessage);
		        }

Thanks.

If this is a copy, set dragDataAction:“copy” on the source grid. As it stands, your code directly modifies the dataset of the source grid as you are trying to eliminate dupes (your removeAt() call).

Hi, Actually when I removed dropRecords.removeAt(i) function above and then changed the newDropRecords to dropRecords and it worked.

Thanks for all your help.

Newt

Thanks for your code it helped me alot. I made some changes and posted a version that worked for me. Hopefully this will help others.

	recordDrop: function (dropRecords, targetRecord, index, sourceWidget) {
		var rolesNotAddedMessage = '';
		for (i=0; i < dropRecords.length; i++) {
			if (selectedRoleList.data.find("roleId", dropRecords.get(i).roleId)) {
				rolesNotAddedMessage = rolesNotAddedMessage + "\'" + dropRecords.get(i).roleName + "\' is already in the list." + "<br>";
			}
			else {
				this.Super("recordDrop", newDropRecords, targetRecord, index, sourceWidget);
			}
			if (rolesNotAddedMessage != ''){	
				isc.say(rolesNotAddedMessage);
			}
		}     
	
	}