javascript - Fastest way to search string for substring using jQuery -
javascript - Fastest way to search string for substring using jQuery -
i using datatables plugin jquery. within datatable have approximately 16 tr rows 4 td columns each. datatables plugin provides api extension allows searching string in cells of table or in cells of specified column.
the search extension returns array of row indices match found. example, [3, 7, 10, 11]. search extension supported exact match search had modify from:
if (val == ssearch)
to:
if (val.indexof(ssearch) > 0)
my customization cause of performance issues i'm having, necessary since contents of cells updated dynamically , hence unpredictable performing exact match search.
an illustration haystack:
<input id="_heatofrejection" class="form-control text-right text-box single-line" type="text" name="heatofrejection" measureid="heatload" value="5000.0" uomid="mbh">
an illustration needle:
' measureid=\"heatload\" '
the average time required perform search needle ~17.5ms , since inner loop contains ~16 different needles outer loop causing additional loops of inner loop, processing time noticeable. it's not horrible, can take 2-3 seconds. on note, not critical function.
what wanting know if there faster way using indexof() perform search. using jquery selector might faster, id unknown/unimportant search. multiple controls can contain needle , have search entire column.
to search element having attribute specific value, can use
$("[measureid='heatload']");
it homecoming elements having attribute 'measureid' value 'heatload'.
javascript jquery search
Comments
Post a Comment