How to perform a search on generated text

How to perform a search on generated text

dkClarkdkClark Posts: 8Questions: 2Answers: 0

I have the following in my server side page.
The data returned and displayed is as I want it.

eg. value in 'db' is 4 it changes 'dt' -> SwitchboardName to 'East Wall' and that is what is shown in the table.

The issue is when I type 'East' in the search fieled it doesn't show.
If I type in 4, it shows.

How can I get it to search the returned text the the table is showing?

...
array(
'db' => 'switchboardID',
'dt' => 'SwitchboardName',
'formatter' => function( $d, $row ) {
global $switchboard_array;
return isset( $switchboard_array[$d]['switchboard'] ) ? $switchboard_array[$d]['switchboard'] : '';
}
),
...

...
var table = $('#myTable').DataTable({
"responsive": true,
"deferRender": true,
"processing": true,
"serverSide": true,
"pageResize": true,
"ajax": "ids-objects.php",
"columns": [
{ "data": "number" },
{ "data": "DT_RowId" },
{ "data": "description" },
{ "data": "type" },
{ "data": "current" },
{ "data": "SwitchboardName" },
{ "data": "active" }
],
"columnDefs": [
{
"targets": [ 1 ],
"visible": false,
"searchable": false
}
],
...

Answers

  • colincolin Posts: 15,142Questions: 1Answers: 2,586

    You would need to do the opposite, i.e. convert back to the number and search for that in your table, then convert those results to use the string.

    Colin

  • dkClarkdkClark Posts: 8Questions: 2Answers: 0

    Thanks for the reply Colin. I don't follow I am afraid. I should have also mentioned that the number is a link to another table. My logic is, I create an array of Switchboard names with ID and then use the id in the datatable script to change the number to the appropriate text for displaying in the table. I haven't been able to find a way to join tables in the datatables syntax. I may have even made it harder for anyone to understand what I am trying to achieve.

  • allanallan Posts: 61,665Questions: 1Answers: 10,096 Site admin

    The issue here is that you are rendering the data you want to search after the search has been done (it is done in SQL, the rendering in PHP once the results have been returned).

    So either you need to do the lookup in SQL (which is readily enough done if you are using a left join to get the data) or the script needs to be modified to get all of the data from the db and do the search in PHP. But to my mind that nullifies any benefit server-side processing offers.

    The final option is to use client-side processing. How many rows of data do you have?

    Allan

  • dkClarkdkClark Posts: 8Questions: 2Answers: 0

    I have changed "serverSide": true to "serverSide": false and in the search box I entered "Shed 8" with " and it gives the desired effect. For the number of records I am only talking 1-200 so not a big issue. Thanks for the help.

This discussion has been closed.