Datetimepicker inside datatable

ast 1 Reputation point
2022-07-21T06:15:36.747+00:00

How to add date time picker inside datable, i try but this working outside of datatable , but inside datatable not working

ASP.NET
ASP.NET
A set of technologies in the .NET Framework for building web applications and XML web services.
3,288 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,309 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Reza Aghaei 4,936 Reputation points MVP
    2022-07-21T09:49:41.377+00:00

    You need the correct styles and scripts. (When it shows outside of the table, it usually means you are missing datetimepicker styles)

    <script type="text/javascript" src="https://code.jquery.com/jquery-3.5.1.js"></script>  
    <script type="text/javascript" src="https://cdn.datatables.net/1.12.1/js/jquery.dataTables.min.js"></script>  
    <script type="text/javascript" src="https://cdn.datatables.net/datetime/1.1.2/js/dataTables.dateTime.min.js"></script>  
    <link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/1.12.1/css/jquery.dataTables.min.css" />  
    <link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/datetime/1.1.2/css/dataTables.dateTime.min.css" />  
    

    You need to use an input for the datetimepicker to show, and preferably use a class to enable the DateTimePicker control:

    <input class="mydatetimepicker" type="text" value="2011-04-25"/>  
    

    You need to call the DateTimePicker plugin:

    <script>  
        $(document).ready(function () {  
            $('#example').DataTable();  
            $('.mydatetimepicker').dtDateTime();  
        });  
    </script>  
    

    Example

    You can find the full example as a jsfiddle. But I also post it here:

    <!DOCTYPE html>  
    
    <html lang="en" xmlns="http://www.w3.org/1999/xhtml">  
    <head>  
        <meta charset="utf-8" />  
        <script type="text/javascript" src="https://code.jquery.com/jquery-3.5.1.js"></script>  
        <script type="text/javascript" src="https://cdn.datatables.net/1.12.1/js/jquery.dataTables.min.js"></script>  
        <script type="text/javascript" src="https://cdn.datatables.net/datetime/1.1.2/js/dataTables.dateTime.min.js"></script>  
        <link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/1.12.1/css/jquery.dataTables.min.css" />  
        <link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/datetime/1.1.2/css/dataTables.dateTime.min.css" />  
        <title>DataTables Example - DateTimePicker</title>  
    </head>  
    <body>  
        <script>  
            $(document).ready(function () {  
                $('#example').DataTable();  
                $('.mydatetimepicker').dtDateTime();  
            });  
        </script>  
        <table id="example" class="display" style="width:100%">  
            <thead>  
                <tr>  
                    <th>Name</th>  
                    <th>Position</th>  
                    <th>Office</th>  
                    <th>Age</th>  
                    <th>Start date</th>  
                    <th>Salary</th>  
                </tr>  
            </thead>  
            <tbody>  
                <tr>  
                    <td>Tiger Nixon</td>  
                    <td>System Architect</td>  
                    <td>Edinburgh</td>  
                    <td>61</td>  
                    <td><input class="mydatetimepicker" type="text" value="2011-04-25"/></td>  
                    <td>$320,800</td>  
                </tr>  
                <tr>  
                    <td>Garrett Winters</td>  
                    <td>Accountant</td>  
                    <td>Tokyo</td>  
                    <td>63</td>  
                    <td><input class="mydatetimepicker" type="text" value="2011-07-25" /></td>  
                    <td>$170,750</td>  
                </tr>  
                <tr>  
                    <td>Ashton Cox</td>  
                    <td>Junior Technical Author</td>  
                    <td>San Francisco</td>  
                    <td>66</td>  
                    <td><input class="mydatetimepicker" type="text" value="2009-01-12" /></td>  
                    <td>$86,000</td>  
                </tr>  
                <tr>  
                    <td>Cedric Kelly</td>  
                    <td>Senior Javascript Developer</td>  
                    <td>Edinburgh</td>  
                    <td>22</td>  
                    <td><input class="mydatetimepicker" type="text" value="2012-03-295" /></td>  
                    <td>$433,060</td>  
                </tr>  
            </tbody>  
            <tfoot>  
                <tr>  
                    <th>Name</th>  
                    <th>Position</th>  
                    <th>Office</th>  
                    <th>Age</th>  
                    <th>Start date</th>  
                    <th>Salary</th>  
                </tr>  
            </tfoot>  
        </table>  
    </body>  
    </html>  
    

    And here is the result:

    223092-dt.png