Solved: Search table, returning any row with a match

I want to be able to search an entire table (linked to a dataset) and return any row that has a matching value (in any column). I searched all over for an answer to this one, but only found examples using filter().or() for two columns.

Anyway, I figured it out, so here is the code in case anyone runs into this issue. The solution was to build a filter tree then setFilter(filter tree).

Note: I use .contains() here, but you can use any of the WixDataFilter functions. Changing the two instances of .contains() to .eq() for example, would return all rows that have a value in them equal to val.

function filterTable(val) {
    var tbl = $w("#tblOrderManagement"); //table: #tblOrderManagement
    var fltr = wixData.filter().contains(tbl.columns[0].dataPath, val);
    for (var i = 1; i < tbl.columns.length; i++) {
      fltr = fltr.or(wixData.filter().contains(tbl.columns[i].dataPath, val));
    }
    $w("#completedOrders").setFilter(fltr); //dataset: #completedOrders
}
2 Likes

Thank you for sharing your work!