Combining Three columns In Search

Combining Three columns In Search

abdallahbedirabdallahbedir Posts: 4Questions: 1Answers: 0
edited May 2018 in Free community support
 {
                    data:'first_name', name:'first_name',
                    render: function(data, type, row, meta) {
                        return `
                        ${row.first_name} ${row.middle_name} 
                        ${row.last_name} 
                    `
                    }, className: 'dt-left, dataTableLeftAlignment', searchable: true, sortable: false
 },

I am displaying first_name , middle_name , last_name in one column but it searches for first_name only , how can I let it search by first_name,middle_name,last_name ?

Answers

  • colincolin Posts: 15,237Questions: 1Answers: 2,598

    Hi @abdallahbedir ,

    That should work fine, see this example here. Can you take a look at my code and see if that helps, and if not, could you create a similar problem demonstrating the problem, please.

    Cheers,

    Colin

  • abdallahbedirabdallahbedir Posts: 4Questions: 1Answers: 0

    Hi @colin ,

    Actually It didn't work like your example , I think because my case is a bit different as I have name property different than data , the below code shows only first_name results when I start searching :
    {
    data:'first_name', name:'clients_translations.first_name',
    render: function(data, type, row, meta) {
    return ${row.first_name} ${row.middle_name}  ${row.last_name} 
    }, className: 'dt-left, dataTableLeftAlignment', searchable: true
    },
    If I changed the code to middle_name , it searches only for middle_name .

    Thanks

  • colincolin Posts: 15,237Questions: 1Answers: 2,598

    Would you be able to create a live example, that would help to understand this?

    C

  • abdallahbedirabdallahbedir Posts: 4Questions: 1Answers: 0

    Yes @colin , just add "serverSide": true, to your example and you will find the issue

  • colincolin Posts: 15,237Questions: 1Answers: 2,598

    Gotcha... take a look at this example here - the problem is because it's not a configured column, it's not part of the search data. I've added the last_name as a hidden column, and now the searches work as expected.

    Does that work for you?

  • abdallahbedirabdallahbedir Posts: 4Questions: 1Answers: 0

    Thanks @colin for the workaround but It's not an efficient solution because If you searches for both first_name & last_name will not work .

  • colincolin Posts: 15,237Questions: 1Answers: 2,598

    As it is, it's not going to be possible. The server-side script searches based on the columns that match the data parameter, and it can't search on the rendered data, since that only works with client-side processing.

    So, you'll either need to modify the server-side script to support searching across parameters, or switch to client-side processing.

This discussion has been closed.