Searching with render function...

Searching with render function...

n000b19n000b19 Posts: 3Questions: 1Answers: 0

Hi,

I am using Datatables with ajax calling a server side script to get the result-set from a MySQL database. For some of the columns, I need to modify the text that needs to be displayed e.g.

data: null,
render: function ( data, type, row, meta ) {
      return row.manufacturer + " (" + row.model + ")";
    }

The column correctly displays the text. But when I try to search for either the manufacture or model, no results come up. I am searching from the UI using the Datatables builtin input box. Any idea how can I include the manufacturer and/or model in the search?

Many Thanks!

This question has an accepted answers - jump to answer

Answers

  • colincolin Posts: 15,240Questions: 1Answers: 2,599

    Hi @n000b19 ,

    When serverSide is enabled, all searches are performed there, so how you render the data on the client would have no bearing, you would need to do the same search on the server side too.

    Hope that helps,

    Cheers,

    Colin

  • n000b19n000b19 Posts: 3Questions: 1Answers: 0
    edited October 2018

    Thanks Colin.

    If I do like

    data: "manufacturer",
    render: function ( data, type, row, meta ) {
          return row.manufacturer + " (" + row.model + ")";
     }
    

    Then the search does return any manufacturers matching the input. I am wondering, if there is a way to define two db columns (manufacturer is column in db, as is model, in the same table) for the data, something like (which does not work :()

    data: "manufacturer,model",
    render: function ( data, type, row, meta ) {
          return row.manufacturer + " (" + row.model + ")";
     }
    
  • kthorngrenkthorngren Posts: 21,303Questions: 26Answers: 4,947
    Answer ✓

    I don't do much with server side processing but maybe you can create table columns for manufacturer and model then hide them using columns.visible. They won't be visible and you can still display the combined using your above column definition. The thought is that the hidden columns would be sent with the other parameters to your server side processing script.

    Kevin

  • n000b19n000b19 Posts: 3Questions: 1Answers: 0

    Thanks kthorngren!

    I think that approach should work :). I'll accept your comment as the answer.

This discussion has been closed.