PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Monday, March 7, 2022

[FIXED] create personaliced filter in datatable with select

 March 07, 2022     datatable, datatables, jquery, laravel-5     No comments   

Issue

i want to create in my datatable one filter personaliced with dropdown but i don´t know where to begin... Sorry it´s my question it´s very bad. I´m reading documentation from datatable reading any forum, and other post from stackoverflow but i don´t know how i can to do.

i need create one filter with this param:

  • new
  • pending
  • null
  • confirm
  • commercialiced
  • confirm-absent
  • confirm-null

i need other dropdown filter but if i do the firts o can to do next.

I need create one select personaliced with this data, and after i need create event and function to controller, etc? i´m working in backend with laravel 5.6. Now i have this code:

initComplete: function () {
            // bottom filter
            this.api().columns([6,8,9]).every( function () {
                var column = this;
                var select = $('<select class="form-control"><option value=""></option></select>')
                    .appendTo( $(column.footer()).empty() )
                    .on( 'change', function () {
                        var val = $(this).val();
                        column.search( this.value ).draw();
                    } );
                
                // If I add extra data in my JSON, how do I access it here besides column.data?
                column.data().unique().sort().each( function ( d, j ) {
                    select.append( '<option value="'+d+'">'+d+'</option>' )
                } );
            } );
        },

but this return actual data en my table and create select. I need create select with x option and after to can search data and fill datatable.

Sorry for my question, and thanks for help me


Solution

With this code i can solve my question:

initComplete: function () {
            // DATE FILTER
            this.api().columns([3]).every( function () {
                var column = this;
                var select = $('<select class="form-control"><option value=""></option></select>')
                    .appendTo( $(column.footer()).empty() )
                    .on('change', function () {
                        var val = $(this).val();
                        column.search( this.value ).draw();
                    } );
                
                // If I add extra data in my JSON, how do I access it here besides column.data?
                select.append( '<option value="nueva">Nueva</option>'+
                                '<option value="confirmada">Confirmada</option>'+
                                '<option value="pendiente">Pendiente</option>'+
                                '<option value="nula">Nula</option>'+
                                '<option value="aplazada">Aplazada</option>'+
                                '<option value="ausente">Ausente</option>'+
                                '<option value="venta">venta</option>'
                            );
            } );

in my question i´m using this code to get all header from my table and created filter. i thinked that i would can use this for created one select in position 3 with my values... And it´s ok



Answered By - scorpions78
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing