Instantiating JQuery Datepicker Input Field in All Rows

Instantiating JQuery Datepicker Input Field in All Rows

c-myers1c-myers1 Posts: 43Questions: 16Answers: 0

So I have a datatable with a column meant to be a datepicker widget.

The datatables formatter correctly gives each datepicker an id of 'datepicker_#' where # is the column row number.

Within my document.ready function, right after instantiating the table, I immediately follow with:

$("#datepicker_1").kendoDatePicker();

This is simply for test purposes, to see it works for the first row before I bother with the selector that grabs all datepickers.

The above command simply has no effect; yet the network and console developer tabs reveal nothing unusual.

What could the issue be?

Please note I'm following the example here https://demos.telerik.com/kendo-ui/datepicker/index (i.e. I have loaded all required assets hitherto)

This question has an accepted answers - jump to answer

Answers

  • bindridbindrid Posts: 730Questions: 0Answers: 119

    Use the createdRow callback in your datatables, something like

    $("#example").DataTable({
        createdRow:function(row,data,index){
           $("#datepicker_1", row).kendoDatePicker();    }
    });
    
  • c-myers1c-myers1 Posts: 43Questions: 16Answers: 0
    edited March 2018

    Would this work:

    $("#example").DataTable({
    createdRow:function(row,data,index){
    $("#datepicker_"+row, row).kendoDatePicker(); }
    });

    To take care of each row and not just the first?

  • c-myers1c-myers1 Posts: 43Questions: 16Answers: 0

    It doesn't work. How do I instantiate for each datepicker_# within createdRow?

  • bindridbindrid Posts: 730Questions: 0Answers: 119
    Answer ✓

    By bad. Don't use an id. Use a class name.

    something like

    $("#example").DataTable({
    columnDefs:[{targets:[3], className:"datepicker_cell"}],
    createdRow:function(row,data,index){
    $(".datepicker_cell", row).kendoDatePicker(); }
    });

    here is my working example using jquery ui datepicker http://jsbin.com/hojexud/edit?html,js,output

  • c-myers1c-myers1 Posts: 43Questions: 16Answers: 0

    Could you please change this js fiddle to get the row selected (and checkbox ticked) once the datepicker is changed?

This discussion has been closed.