javascript - jquery 数据表中的日期选择器不工作

标签 javascript jquery datatable datepicker

数据表上的日期选择器遇到一些问题。我在页面顶部设置了两个测试日期选择器,它们工作正常。

我的问题是,当我在 aoColumns 中选择 '{type:"date-range"} 时,我收到一条错误消息,告诉我 from.datepicker() 是不是一个函数。

我尝试了所有其他类型的过滤器(选择、数字范围等),除了日期范围之外,所有过滤器都工作正常。

任何人都可以帮助我解释为什么我的 JavaScript 使用 type:"date-range"时似乎会崩溃。我似乎无法弄清楚为什么它不能像此处所示的示例那样工作 http://jquery-datatables-column-filter.googlecode.com/svn/trunk/dateRange.html

下面是代码

<body>
    <div id="content">
        </div><div id='assignments_view'>
        <h1>Assignments</h1><br/>
From:<input type="text" name="start_date" value="" id="dateStart" placeholder="start Date"  /><br/>
To:<input type="text" name="end_date" value="" id="dateEnd" placeholder="End Date"  /><br/>

<button id = "addNewAssignmentButton">Add New Assignment</button>
    <div id="assignmentTableDiv">

    <table id="assignmentTable" class="fht-table" >
        <thead>
            <tr>
                <th>Name</th>                   
                <th>Basic Information</th>
                <th>Submitter</th>
                <th>Status</th>
                <th>Area</th>
                <th>Start Date</th>
                <th>End Date</th>
                <th>Shopping Cart</th>
                <th>Purchase Order</th>
            </tr>
        </thead>
        <tbody>
<tr class = "assignmentRow" ondblclick="document.location = 'assignments/load_individual_assignment_view/21 '">
        <td>Test assignment</td>
        <td>basic Info for test assignment</td>
<td class = 'status'>review</td> 
        <td>2013-01-08</td>
        <td>2013-01-01</td>
                    </tr>

        </tbody>
        <tfoot><tr class = "footer">
            </tr></tfoot>
    </table>
</div>
</div>


<script
src="//ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script>window.jQuery || document.write('<script src="http://localhost/ahb/js/libs/jquery-1.7.1.min.js"><\/script>')</script>

<script src="http://localhost/ahb/js/libs/jquery-ui-1.8.20.custom.min.js"></script>
<script>
$(document).ready( function () {


var oTable = $('#assignmentTable')
            .dataTable( 
            {
                "bJQueryUI": true,

                }
            )
            .columnFilter({ sPlaceHolder: "head:before",
                            aoColumns: [    null,null,{type:"select"},null,null,
                            null,
                            {type:"date-range"},
                            null,
                               null,                                                
                                        ]}
            );
});

</script>



<script src="//ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>

<script>window.jQuery || document.write('<script src="http://localhost/ahb/js/libs/jquery-1.7.1.min.js"><\/script>')</script>

<script src="http://localhost/ahb/js/libs/jquery-ui-1.8.20.custom.min.js"></script>
<script>
$('#dateStart').datepicker({ dateFormat: "yy-mm-dd" });
$('#dateEnd').datepicker({ dateFormat: "yy-mm-dd" });
</script>


<div id="footer">
<footer>
    Page rendered in <strong>0.0951</strong> seconds
</footer>
</div>
<!-- JavaScript at the bottom for fast page loading -->
<!-- Grab Google CDN's jQuery, with a protocol relative URL; fall back to local if     offline -->
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script>window.jQuery || document.write('<script src="http://localhost/ahb/js/libs/jquery-1.7.1.min.js"><\/script>')</script>
<!-- scripts concatenated and minified via build script -->
<script src="http://localhost/ahb/js/plugins.js"></script>
<script src="http://localhost/ahb/js/script.js"></script>
<script src="http://localhost/ahb/js/jquery-placeholder.js"></script>
<script src="http://localhost/ahb/js/libs/jquery.dataTables.min.js"></script>
<script src="http://localhost/ahb/js/libs/jquery.dataTables.columnFilter.js">      </script>
<script src="http://localhost/ahb/js/libs/tabletools.js"></script>

<!-- end scripts -->
</body>
</html>

最佳答案

已解决。 1.8.2 的两个脚本存在冲突,导致 jQuery datepicker 无法工作。我只需删除一个脚本并在页面底部仅保留一个版本的 1.8.2.min。

关于javascript - jquery 数据表中的日期选择器不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14159774/

相关文章:

javascript - AngularJs:如何翻译日期对象?

jquery - 使用 jQuery 更改日期格式适用于 Firefox 和 Chrome,但不适用于 Safari?

javascript - Jquery模态: on background click add class and remove html

jquery - 如何让图片一个接一个滚动

c# - 将两个数据表中的值添加到一个新数据表中

jquery - 通过包含 DataTables 的 jQuery UI 集成,在 Shiny 的应用程序中使用 DataTables

javascript - 如何在数据内容属性中换行?

javascript - "array is not a function"错误

r - 添加具有 TRUE/FALSE 的列并将其显示为复选框

javascript - Android 视频插件 Phonegap with Cordova 2.2.0