Using API in callbacks - One Column

Using API in callbacks - One Column

datatablenoobdatatablenoob Posts: 2Questions: 1Answers: 0

I was wondering how to use the API in callbacks so that only the first column when clicked caused the search of the persons name? I guess I would want the callback to trigger off a specific tr ID rather than an entire tr.

Answers

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin

    I would suggest that for a column click you want to match off a class name rather than an id.

    See this example for how to use an event on the table. You could simply use columns.className to add a class for the column you want to select and modify the jQuery selector for the event handler.

    Allan

  • datatablenoobdatatablenoob Posts: 2Questions: 1Answers: 0

    Hey Allan,

    Thank you for responding. I tried applying what you stated, but I failed. I have posted my current code snippet below, prior to the attempt, could you please give me some direction.

    Thank you!

    I would like to only have the column that says "search this column" be the column that has its tr ID applied to the "search filter" when an item in this column is clicked on.

        $(document).ready(function() {
            TableTools.DEFAULTS.aButtons = [ "copy", "xls", "print" ];
            var oTable = $('#results_table').dataTable({
                "bFilter": true,
                "bSort": true, //true
                "bInfo": true,
                "sScrollX": getWidth(),
                "aaSorting": [[ 0, "desc" ]],
                "aoColumns": [
                    {"sType": "num-html"},
                    null,
                    null,
                    null, //search on this column, this has no name an a dynamic id that can be retrieved with this
                    null,
                    null,
                    null,
                    null,
                    null,
                    {"bSort":null},
                    null
                    ],
                "initComplete": function () {
                    var api = this.api();
                    api.$('td').click( function () {
                        api.search( this.innerHTML ).draw();
                    });
                }           
            }).fnSetFilteringDelay();
    
  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin

    I would like to only have the column that says "search this column" be the column that has its tr ID applied to the "search filter" when an item in this column is clicked on.

    I'm afraid I don't understand. Do you mean the "cell ID"? If so, how it is being set? Even then I don't really understand - you want to use the cell's id as the search parameter for the table?

    Can you link to a page showing what you currently have please.

    Allan

This discussion has been closed.