Is there a simple way to search my embedded cloudtable for 1 row which has a match in 1 column ?

Is there a simple way to search my embedded cloudtable for 1 row which has a match in 1 column ?

pmarks906dpmarks906d Posts: 61Questions: 18Answers: 0

I have an embedded cloudtable on my page called "Table". One of its columns is called "SequenceNumber" which contains a unique integer in each row. How can i simply and efficiently use javascript to search the table embedded on my page and return only that single row of data which has a particular "Sequence Number"? I know I can write a loop which reads each row until i find the correct "SequenceNumber" but I am hoping for a solution which is shorter, simpler, and more efficient. I've looked through the docs and forum but I just can't seem to find or figure out the solution. I've tried reading the "SequenceNumber" column into an array and getting the index of the matching value, but the column array and my table rows seem to be ordered differently. Thanks.

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 63,516Questions: 1Answers: 10,472 Site admin
    Answer ✓

    Hi,

    You've probably seen how to access a DataTable's API for CloudTables already? Assuming that to be the case, the question becomes how to use the API to select the row.

    That is done using the row() method with a suitable row-selector. In this case, a function might be the best option - e.g.:

    let rowData = table
      .row(function (idx, data) {
        return data['dp-12'] === searchTerm;
      })
      .data();
    

    Where dp-12 would be replace with whatever the id of the data point is that you are searching on.

    Regards,
    Allan

Sign In or Register to comment.