dsfliu1129 2012-10-11 05:51
浏览 74
已采纳

如何将时间戳添加到jquery jtable?

I am using jQuery jTable in my PHP site to display table and to add a record / modify a record to the table.

I have few fields which have time values. Unfortunately jTable supports only a datepicker, not a timepicker. Can anyone suggest how to add jQuery timepicker to the jTable?

I tried to add few JQuery Time Picker in the main JTable.js file. But I Think i'm adding wrongly. Since i'm new to jquery, i can't figure out how to add the JQuery Time Picker Plugin

   <div id="ShiftTableContainer" style="width: 600px;"></div>
    <script type="text/javascript">

        $(document).ready(function () {

            //Prepare jTable
            $('#ShiftTableContainer').jtable({
                title: 'Shift',
                actions: {
                    listAction: '../m/ShiftActions.php?action=list',
                    createAction: '../m/ShiftActions.php?action=create',
                    updateAction: '../m/ShiftActions.php?action=update',
                    deleteAction: '../m/ShiftActions.php?action=delete'
                },
                fields: {
                    id: {
                        title: 'Shift Id',
                        width: '25%'
                    },
                    name: {
                        title: 'Shift Name',
                        width: '40%'
                    },
                    start_time: {
                        title: 'Start Time',
                        width: '75%',
                        input: function (data) {
                                var dt = data.record ? data.record.start_time : NULL;
                                return '<input type="text" style="width:200px" value="' + dt + '" />';
                            }
                        inputClass: 'timepicker'
                    },

                    end_time: {
                        title: 'End Time',
                        width: '75%',

                        //options: { '1': '101', '2': '102' }
                    },
                    description: {
                        title: 'Description',
                        width: '75%'
                    },
                    color: {
                        title: 'Color',
                        width: '75%',
                        //options: { '1': '101', '2': '102' }
                    },
                    break_schedule: {
                        title: 'Break Schedule',
                        width: '75%',
                    }
                }

            });

            $('#ShiftTableContainer').jtable('load');
        });



    </script>
            <script>
            $(function(){
                  $("input.timepicker").datetimepicker();
                });     

    </script>   
  • 写回答

4条回答 默认 最新

  • duanhuoyao7011 2012-10-12 11:00
    关注

    I tried like this and its working fine. I updated JQuery and JQuery UI to the latest version. Imported it in my php along with the timepicker plugin i am using. I did some modification in my code. Here is the working code.

            <script type="text/javascript">
    
            $(document).ready(function () {
    
                //Prepare jTable
                $('#ShiftTableContainer').jtable({
                    title: 'Shift',
                    actions: {
                        listAction: '../m/ShiftActions.php?action=list',
                        createAction: '../m/ShiftActions.php?action=create',
                        updateAction: '../m/ShiftActions.php?action=update',
                        deleteAction: '../m/ShiftActions.php?action=delete'
                    },
                    fields: {
                        id: {
                            key: true,
                            edit: false,
                            title: 'Shift Id',
                            width: '25%'
                        },
                        name: {
                            title: 'Shift Name',
                            width: '40%'
                        },
                        start_time: {
                            title: 'Start Time',
                            width: '75%'
                        },
    
                        end_time: {
                            title: 'End Time',
                            width: '75%'
                        },
                        description: {
                            title: 'Description',
                            width: '75%'
                        },
                        color: {
                            title: 'Color',
                            width: '75%',
                            //options: { '1': '101', '2': '102' }
                        },
                        break_schedule: {
                            title: 'Break Schedule',
                            width: '75%',
                        }
                    },
                    formCreated: function (event, data) 
                    {
                        var $input_start_time = data.form.find ('input[name="start_time"]');
                        $input_start_time.addClass("time");
                        $input_start_time.timepicker();
    
                        var $input_end_time = data.form.find ('input[name="end_time"]');
                        $input_end_time.addClass("time");
                        $input_end_time.timepicker();
    
                    }
                });
    
                $('#ShiftTableContainer').jtable('load');
    
            });
    
    
    
        </script>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog