Individual column searching NOT WORKING

Individual column searching NOT WORKING

daniel89fgdaniel89fg Posts: 5Questions: 1Answers: 0

Hello.
I have a problem, not working filter data by column.
I put my code:

It does not work---

var table = $('#listado').DataTable({
"bFilter": false,
"scrollX": true,
"aaSorting": [[ 0, "asc"]],
"language": {
"url": "<?php echo base_url() ?>plugins/datatables/languages/<?php echo $this->lang->lang() ?>.json"
}
});

// Apply the search
table.columns().every( function () {
    var that = this;

    $( 'input', this.footer() ).on( 'keyup change', function () {
        that
            .search( this.value )
            .draw();
    } );
} );

it works---

var table = $('#listado').DataTable();

// Apply the search
table.columns().every( function () {
    var that = this;

    $( 'input', this.footer() ).on( 'keyup change', function () {
        that
            .search( this.value )
            .draw();
    } );

You know what the problem is? please help! Thank You.
} );

Answers

  • allanallan Posts: 63,692Questions: 1Answers: 10,500 Site admin

    Per the forum rules, can you link to a test case showing the issue in future please.

    IN this case you need to put your search code into initComplete since you are using Ajax to load the table's data (recall what the first letter of Ajax stands for :-) ).

    Allan

  • daniel89fgdaniel89fg Posts: 5Questions: 1Answers: 0
    edited July 2015

    Hello.

    No use Ajax to load data in the table. The table is loaded into html / php and then run the script.

    If I create an empty datatable without options if it works, if it does not work I think with options.

  • allanallan Posts: 63,692Questions: 1Answers: 10,500 Site admin

    Yes sorry - you are using Ajax to load the language data, rather than the table data. In which case the same applies - use initComplete to initialise your search inputs.

    Allan

  • daniel89fgdaniel89fg Posts: 5Questions: 1Answers: 0

    ok, as you would with InitComplete?

  • daniel89fgdaniel89fg Posts: 5Questions: 1Answers: 0
    edited July 2015

    this does not work!!!

    var table = $('#listado').DataTable({
            "bFilter": false,
            "scrollX": true,
            "aaSorting": [[ 0, "asc"]],
            "language": {
                "url": "<?php echo base_url() ?>plugins/datatables/languages/<?php echo $this->lang->lang() ?>.json"
            },
            "initComplete": function() {
                table.columns().every( function () {
                var that = this;
         
                $( 'input', this.footer() ).on( 'keyup change', function () {
                    that.search( this.value ).draw();
                } );
            } );
            }
        });
    
  • allanallan Posts: 63,692Questions: 1Answers: 10,500 Site admin

    Can you link to the page so I might debug it please.

    Allan

  • daniel89fgdaniel89fg Posts: 5Questions: 1Answers: 0

    Sorry, I work on localhost, not online.

  • allanallan Posts: 63,692Questions: 1Answers: 10,500 Site admin

    I'm afraid there is little I can do to offer any help in that case. I would need a test case showing the issue so I can debug it.

    Allan

This discussion has been closed.