I currently have a DataTable that has a column containing a string of numeric values such in the format of '14,11,10'. They can only be a maximum of two digits long, but the number of values can vary. It could be a single value such as '11' or as many as four values within the string '16,14,10,21'.
In addition, I have a match handler and a select2 box that contains all of the potential number values. A user can either select to match 'Any', which will match every result if the number string contains at least one of the selected numbers. Selecting 'Match All' will only search for the specific combination, no matter the order of the numbers.
<select class="form-control form-control-alternative" id="syngery_match" name="syngery_match">
<option value="any">Match Any</option>
<option value="all">Match All</option>
</select>
<select class="form-control form-control-alternative synergies-multi select2-hidden-accessible" name="synergies[]" multiple="" id="synergies" data-select2-id="synergies" tabindex="-1" aria-hidden="true">
<option value="1">NP</option>
<option value="2">BL</option>
<option value="3">X</option>
<option value="4">BM</option>
<option value="5">TN</option>
<option value="6">DK</option>
<option value="7">AD</option>
<option value="8">WK</option>
<option value="9">WM</option>
<option value="10">RS</option>
<option value="11">M</option>
<option value="12">1T</option>
<option value="13">TK</option>
<option value="14">WC</option>
<option value="15">SP</option>
<option value="16">FB</option>
<option value="18">HH</option>
<option value="19">DZ</option>
<option value="20">CP</option>
<option value="21">HT</option>
<option value="22">CS</option>
</select>
Match Any
I have this part working aside from one minor issue with the single digit numbers.
Example Input: [1,22,16]
if ($("#syngery_match").val() == "any")
{
var any_string = $(this).val().toString();
var select_snys = any_string.replace(',', '|');
players_table.columns("#synergies_column").search(select_snys, true, false).draw();
}
Since 1 was included in the string of numbers, it returns rows that contain values such as 11,12,13....19, 21, etc. How would I go about altering my code so the rows returned have to contain the exact number in the string and not just a part of the number?
Match All
This part is also partially working. The only issue here is that the string of numbers entered only returns rows with the numbers in that exact order.
Target Row: [13,15,6]
Example Input: [6,13,15]
Example Input 2: [15,13,6]
The two example inputs return no results as the numbers were entered out of order compared to the column on the table.
else if ($("#syngery_match").val() == "all")
{
var any_string = $(this).val().toString();
players_table.column("#synergies_column").search(any_string, true, false).draw();
}
Hopefully I was able to explain my situation clearly enough. Any help would be appreciated!