Searchable Not Working

Searchable Not Working

naini43naini43 Posts: 3Questions: 1Answers: 0

Hi all,

I am new to this datatables. I have some question regarding the searchable column. This is my code that is not working. I need to make the 5th column not searchable and invisible. However, this code causes the column(6) is not searchable by column(6).search("some value")

"columnDefs": [
{
"targets": [4,6],
"visible": false,
"searchable": true
},{
"targets": [ 5 ],
"visible": false,
"searchable": false
},
{ "orderable": false, "targets": [0, 7] }
]

before this it was like this (this is working but the 5th column is searchable)

"columnDefs": [
{
"targets": [4,6,5],
"visible": false,
"searchable": true
},
{ "orderable": false, "targets": [0, 7] }
]

Answers

  • hhmhhm Posts: 24Questions: 3Answers: 2
    edited September 2014

    For better readability I prefer the options to be separated:

    "columnDefs": [ { "targets": [4,6,5], "visible": false, "searchable": true }, { "orderable": false, "targets": [0, 7] } ]
    

    would become

        $(document).ready(function() {
            $('#example').DataTable();
            "columnDefs": [
                {
                    "visible": false,
                    "targets": [ 4, 5, 6 ]
                },
                {
                    "searchable": true,
                    "targets": [ 4, 5, 6 ]
                },
                {
                    "orderable": false,
                    "targets": [ 0, 7 ]
                }
            ]
        });
    

    For me this way it is much easier to see which option applies to which column.

    Edit: ...and if I could get the Markdown syntax formatting working, it would even look proper.

    HTH, Hans

  • naini43naini43 Posts: 3Questions: 1Answers: 0

    Hi,

    Thank you for the reply. I am sorry im not sure how to put this in code style. I have also tried your way but so far havent got the result that i need. This is one of the code that i tried.

        var oriTable = $("#originalList").DataTable({
            "initComplete" : function(){
                $("#loadingDiv").hide();
                $("#selectUserDiv").show();
            },
            "columnDefs": [
                {
                    "visible": false,
                    "targets": [4,5,6]
                },{
                    "searchable": false,
                    "targets": [ 5 ]
                },{
                    "searchable":true,
                    "targets" : [4,6]
                },
                { "orderable": false, "targets": [0, 7] }
            ]
        });
    
  • hhmhhm Posts: 24Questions: 3Answers: 2

    Sorry, I missed something in my post. Columns are visible, searchable and so on by default. So the only option there is is to switch things off (do not thing invisible, think not visible).

    Thus declaring searchable true for columns 4 and 6 is redundant and seems to overwrite the setting of searchable you make before.

    var oriTable = $("#originalList").DataTable({
        "initComplete" : function(){
            $("#loadingDiv").hide();
            $("#selectUserDiv").show();
        },
        "columnDefs": [
            {
                "visible": false,
                "targets": [4,5,6]
            },{
                "searchable": false,
                "targets": [ 5 ]
            },{
                "orderable": false,
                "targets": [0, 7]
            }
        ]
    });
    
  • naini43naini43 Posts: 3Questions: 1Answers: 0

    Hi,

    Thank you again. I also tried the way that you show above. I found out what is the issue.
    Before this all column are searchable, so i have total of 8 column that are searchable with index (0-7).
    I am doing the searching for the 6 column from the table like this

    oriTable.column(6).search(this.value ).draw();
    

    After i put the column index 5 to searchable false. I think somehow the column count become 7 (only column 0-6 are left after the column 5 searchable is set to false). so my code must change to this

    oriTable.column(5).search(this.value ).draw();
    

    is this the way its suppose to be. or is this a bug.

This discussion has been closed.