My form has 2 grids on it. When you select a record from the first grid, it will populate the second grid with related records. This secondary grid has a "PEERGROUP" column, and would contain values like "1", "2", etc.
I need to ensure that a user has selected at least 1 record belonging to every group.
I'm stuck on trying to build a list containing unique Group ID values:
function CheckSelectionForGroups(gridName)
{
//Get rows in grid
var view = $('#' + gridName).data('kendoGrid').dataSource.view();
//Array to store the all distinct groups in the grid
var listOfGroups = [];
var listIndex = 0;
//Loop over the rows in the grid
for (var i = 0; i < view.length; i++)
{
//If the group is found in our list already, do nothing
if (listOfGroups[view[i].PEERGROUP])
continue;
//If the group was not found in our list, add it to the list.
listOfGroups[listIndex] = view[i].PEERGROUP;
listIndex = listIndex + 1;
}
//TODO - Loop over user selection
// and compare groups against list of groups
}
And here is a screenshot of some values:
(Note: The array is incomplete, because if I take a screenshot after processing the next row, it would incorrectly contain 3 values: "1"
, "1"
, and "2"
)
So in this case, I want listOfGroups
to only contain the values "1"
and "2"
. The if
statement inside my for
loop never evaluates to true. I suspect Javascript is casting "1"
to a 1
and is trying to pull the element from listOfGroups
at index 1
. But I don't know how to fix that?
You can use an object to gather the IDs, then use Object.keys
to get an array of those IDs:
var dummyObject = {};
for (var i = 0; i < view.length; i++) {
dummyObject[view[i].PEERGROUP] = 0;
}
var listOfGroups = Object.keys(dummyObject);
Firebase Cloud Functions: PubSub, "res.on is not a function"
TypeError: Cannot read properties of undefined (reading 'createMessageComponentCollector')
So basically when the component mounts, I have an event listener listen for resize eventsIt toggles the isMobileView state and then passes it into the children as a prop
This question already has an answer here:
I'm fairly new to coding and currently working on the Wikipedia viewer project on FCCI have two callback functions that rely on an AJAX request and use the same data, one to suggest searches as the user types into an input and one to display results when they hit enter