How to use datePicker in Column Filter ?

How to use datePicker in Column Filter ?

manigopalmanigopal Posts: 11Questions: 3Answers: 0

I want to use dataPicker for only one column in Column Filter since one column has dates in it.

tried this.,

<script>
$( function() {
 $( "#example1 tfoot th:nth-child(0)".datepicker();
} );    
</script>
 
<script>
    $(document).ready(function() {
    // Setup - add a text input to each footer cell
    $('#example1 tfoot th').each( function () {
        var title = $(this).text();
        $(this).html( '<input type="text" placeholder="Search '+title+'" />' );
    } );
  
    // DataTable
    var table = $('#example1').DataTable();
  
    // Apply the search
    table.columns().every( function () {
        var that = this;
  
        $( 'input', this.footer() ).on( 'keyup change clear', function () {
            if ( that.search() !== this.value ) {
                that
                    .search( this.value )
                    .draw();
            }
        } );
    } );
} );
 </script>

but nothing worked. Screenshot added for reference too.

Answers

  • manigopalmanigopal Posts: 11Questions: 3Answers: 0

    also tried this.,

    <script>
    $( function() {
     $( "#example1 tfoot th:nth-child(1) input[type='text']".datepicker();
    } );    
    </script>
    
  • tangerinetangerine Posts: 3,350Questions: 37Answers: 394

    Please don't make duplicate posts.

  • manigopalmanigopal Posts: 11Questions: 3Answers: 0

    Okay., @tangerine

    any idea of making it work ?

  • colincolin Posts: 15,144Questions: 1Answers: 2,586

    We're happy to take a look, but as per the forum rules, please link to a test case - a test case that replicates the issue will ensure you'll get a quick and accurate response. Information on how to create a test case (if you aren't able to link to the page you are working on) is available here.

    Cheers,

    Colin

  • manigopalmanigopal Posts: 11Questions: 3Answers: 0
    edited April 2020

    @colin @tangerine

    https://datatables.net/extensions/fixedcolumns/examples/styling/col_filter.html

    the above one is that i use., in that search option is of all text or even select option is there for column filter but i need datePicker in that only for my first column.,

    The codes that i tried.,

    and

    https://jsbin.com/qitilos/edit?html,output

  • tangerinetangerine Posts: 3,350Questions: 37Answers: 394

    Your test page reports several console errors. Also you are including two different versions of jQuery js.

  • manigopalmanigopal Posts: 11Questions: 3Answers: 0

    yes

  • colincolin Posts: 15,144Questions: 1Answers: 2,586

    That'll be the place to start then. Can you clear those errors so the problem is visible, please.

    Colin

  • manigopalmanigopal Posts: 11Questions: 3Answers: 0
    edited April 2020

    @colin if i use input type="date" instead of input type="text"

    all column search are working fine with dataPicker in all columns.,

    <script>
        $(document).ready(function() {
        // Setup - add a text input to each footer cell
        $('#example1 tfoot th').each( function () {
            var title = $(this).text();
            $(this).html( '<input type="text" placeholder="Search '+title+'" />' );
        } );
     
        // DataTable
        var table = $('#example1').DataTable();
     
        // Apply the search
        table.columns().every( function () {
            var that = this;
     
            $( 'input', this.footer() ).on( 'keyup change clear', function () {
                if ( that.search() !== this.value ) {
                    that
                        .search( this.value )
                        .draw();
                }
            } );
        } );
    } );
     </script>
    
    

    AND even i have added default datatable from example : https://datatables.net/extensions/fixedcolumns/examples/styling/col_filter.html

    @ https://jsbin.com/zaneyij/edit?js,output

    even at this i cant make it work.,

  • colincolin Posts: 15,144Questions: 1Answers: 2,586

    The test case still isn't loading for me, I'm afraid. Please can you get it working with and provide steps on how to reproduce the problem.

    Colin

  • manigopalmanigopal Posts: 11Questions: 3Answers: 0

    @colin

    i have updated the code again here,
    @ https://jsbin.com/zaneyij/edit?js,output

    in this for first column alone i need to have #datePicker all other should remain #textBox

    Code i have tried to achieve it, you can find it in JS tab

    $(document).ready(function() {
        // Setup - add a text input to each footer cell
        
          $('#example tfoot tr th:first-child').each( function (i) {
            var title = $(this).text();
            $(this).html( '<input type="text" placeholder="Search '+title+'" data-index="'+i+'" />' );
        }
    )
    
This discussion has been closed.