I need to use Corvid code to select a specific Table row, based on the value of one of the cells in the row, rather than selecting by Index. As far as I can tell, there is no straightforward way to do this. Can anyone suggest a way? Thanks!
Hi Steve
Do you mean by value of a cell, the label of the column?
If so, you can map the items in the table to that column, then get the index of that value that you’re looking for and then use the selectRow() function.
Hope this helps~!
Ahmad
First of all sorry for the “redundant” post. I was just trying to clarify the question. I deleted the post as you requested. I do not understand your answer. Could you give me a short code sample? Thanks!
You need to get the data from the table first,
let tableRows = $w("#myTable").rows;
Then, you need to map the data to a field in these rows,
let mappedRows = tableRows.map(items => items.memberId)
Now check if the provided value has a match or not.
let userIndex = mappedRows.indexOf(user.id);
if (userIndex !== -1) {
let userRow = tableRows[userIndex];
$w("#myTable").selectRow(userIndex);
} else {
// handle the case where the provided value doesn't exist
}
Hope this helps~!
Ahmad
Please reply to the answer itself by clicking on the reply button under each answer.
I’ll give it a try. Thanks so much. I really appreciate it!
You’re welcome
OK, just one clarification: in the code above, is memberId the name of the field, not the label of the column its displayed in?. In this screenshot …
the PersonFullName field is what I want to select by. Here is the code I am using:
export function btnTest_click(event) {
console.log( “starting btnTest_mouseOut” );
// get person to find
let varPersonToFind = $w( “#textPersonName” ).text
let tableRows = $w( “#tableMembers” ).rows;
console.log( "rows = " + tableRows);
//map the data to a field in these rows,
let mappedRows = tableRows.map(items => items.PersonFullName)
// check if the provided value has a match or not.
let userIndex = mappedRows.indexOf(varPersonToFind)
console.log( "userIndex = " + userIndex);
if (userIndex !== - 1 ) {
console.log( “if condition met” );
let userRow = tableRows[userIndex];
$w( “#textMemberIndex” ).text = userRow
$w( “#tableMembers” ).selectRow(userIndex);
} else {
// handle the case where the provided value doesn’t exist
console.log( “if condition NOT met” );
}
console.log( “end of function” );
}
and here are the console log results
starting btnTest_mouseOut
Copy of TREE Line 141
rows = [object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Copy of TREE Line 145
userIndex = -1
Copy of TREE Line 150
if condition NOT met
Copy of TREE Line 158
end of function
So I’m guessing something is wrong with this line:
let mappedRows = tableRows.map(items => items.PersonFullName)
I’m not clear on what is supposed to go where I put “PersonFullName”
No, the memberId is the ID of the column that represents the member ID, for example col0, col1, etc …
let mappedRows = tableRows.map(items => items.col[0])
Please note that the count is started from 0, not 1, so if the column is the third one, its index will be 2.
still not getting it. i cannot find an API entry explaining the line
mappedRows = tableRows . map ( items => items . memberId )
i hate to keep asking for help, but… what are the steps to go though to determine the value of memberId
Hey Steve
Map is pure JavaScript, not an API provided by Wix Corvid.
As I explained in my previous reply, the orange property is the column ID that represents the members ID in your specific case.
Please read my previous replies carefully.