Reputation: 63
I have a JQuery Bootgrid with two formatters needed to format correctly a date and euro values columns (in the rows I store the date as string in the format YYYYMMDD to get the column ordered correctly if the user choose to order that column, while the table output is in the date format DD/MM/YYYY. Also, I simply add the € symbol to the euro output values.
Put very simply, the default search feature of JQuery Bootgrid searches the original values, not the formatted ones, while I surely need to give to the user the ability to search the formatted values. If you have a solution or even a workaround please help me!
Upvotes: 0
Views: 695
Reputation: 945
I was facing a similar problem, where the search was looking at the original data rather than the formatted data, but needed the original data for sorting.
What I did was set data-searchable="false"
on the formatted column, and then added a new column with the date already formatted by myself. This new column was then set to data-visible="false"
. The table structure was something along the lines of:
<table>
<thead>
<tr>
<th data-column-id="date" data-formatter="dateNoTimeFormat" data-searchable="false">Report Date</th>
<th data-column-id="formattedDate" data-visible="false"></th>
</tr>
</thead>
<tbody>
<tr>
<td><?php echo $reportDate; ?></td>
<td><?php echo date('d/m/Y', strtotime($reportDate)); ?></td>
</tr>
</tbody>
</table>
By default, the bootgrid search doesn't include the hidden columns, so the source also needs modifying slightly. There is a function containsPhrase(row)
in jquery.bootgrid.js
(line 172 in v1.3.1) which has an if
statement reading:
if (column.searchable && column.visible &&
column.converter.to(row[column.id]).search(searchPattern) > -1)
{
return true;
}
The && column.visible
needs removing from the code, meaning the search will also look at columns set to be hidden.
Upvotes: 1
Reputation: 35
If you're working off a data source, you could always normalize the search from the backend (i.e. the json provider).
Enhancing an existing table - well, Grid.prototype.search is the function.
Upvotes: 1