Highlight custom search values

Highlight custom search values

FedericoVFedericoV Posts: 35Questions: 9Answers: 0

In my Datatables I use the searchHighlight plugin to highlight the search values...I find it useful.
Now I'm trying to get rid of the standard search form and replace it with custom form/search.
The custom form seems working fine...but the searched values are not highlighted into the Datatables...is there a way to fix the issue?
Thanks a lot for any help.
Below the custom search code:

table.DataTable({
        dom: 'lrtip',
        responsive: true,
        autoWidth: false,
        searchDelay: 500,
        processing: true,
        serverSide: true,
        stateSave: true,
        lengthMenu: [[15, 25, 50, -1], [15, 25, 50, "All"]],
        searchHighlight: true,
        ajax: {
            url: "<?php echo site_url('rmidev/domestic_list')?>",
            type: "POST",
            "data": function ( d ) {
                d.csrf_test_name = token_hash;
                // Read values
                var keyword = $('#exampleInput').val();
                d.keyword = keyword;
            },
            "dataSrc": function ( json ) {
                token_hash = json['csrf_test_name'];
                for(var i=0; i< json.data.length; i++){
                    json.data[i].mm = '<a href="' + controller_url + '/data/' + json.data[i].id + '">' + json.data[i].mm + '</a>';
                }
                return json.data;
            }
        },
        order: [[2, 'asc']],
        deferRender: true,
        columns: [
            {data: 'mm'},
            {data: 'ditta'},
            {data: 'tipo'},
            {data: 'motori'},
            {data: 'nc'},
        ],
        columnDefs: [
            {
                targets: [ 3, 4 ],
                orderable: false,
                searchable: false,
            },
        ],
        "language": {"url": "<?php echo site_url('assets/public/plugins/datatables/lang/dataTables.') . $actual_lang . '.lang'; ?>"},
        "pagingType": "numbers",
    });
};

This question has an accepted answers - jump to answer

Answers

  • kthorngrenkthorngren Posts: 21,343Questions: 26Answers: 4,954
    Answer ✓

    I'm guessing this is what you are using to search?

                "data": function ( d ) {
                    d.csrf_test_name = token_hash;
                    // Read values
                    var keyword = $('#exampleInput').val();
                    d.keyword = key
    

    If so the problem is you aren't using the search() aPI to perform the search. In this case you can use the code shown in the Simple Integration section of the docs to perform the highlight using the search term from your custom form.

    Kevin

  • FedericoVFedericoV Posts: 35Questions: 9Answers: 0

    Thanks a lot kevin...I'll give a try at the code in that page

This discussion has been closed.