javascript - 单击分页 Bootstrap 表时不显示日期选择器

标签 javascript jquery datepicker pagination html-table

我用文本框日期选择器创建了一个 boostrap 表。

此文本框日期选择器显示在第 1 页, 但我有一个问题,当下一个分页 boostrap 表时。 此文本框日期选择器未显示,当我返回第 1 页时 日期选择器不显示。我该如何解决这个问题?

第 1 页

enter image description here

第 2 页

enter image description here

这是我的代码。

索引.jsp

    <div class="row">
                <table  data-filter-control="true" data-sortable="true" data-url="data.jsp"  class="table table-bordered table-striped table-condensed" data-toggle="table" data-search="true" data-pagination="true" id="table"></table>
                        </div>
function operateFormater(value, row, index)
    {
        return ["<input type='text'  id='tgl_setor_"+row.id+"' readonly style='background-color:white' onchange='save_data_tgl("+row.id+","+row.no_form_send+")' class='form-control datepicker' />"];
    }


var $table = $('#table');
    function initTable(){
            $table.bootstrapTable({
                columns: [
                    [

                        {
                            field : "no_form",
                            title : "No Formulir",
                            width : '3%',
                            sortable :  true,
                            align:'center'
                        },
                        {
                            field : "tgl_setor",
                            title : "Tanggal Setor",
                            width : '3%',
                            sortable :  true,
                            formatter: operateFormater
                        }
                    ]
                ]
            });
        }


    $table.on('load-success.bs.table', function (d)
    {
            $('.datepicker').DatePicker({
                    orientation: "top",
                    autoclose: true,
                    todayHighlight: true,
                    format: 'yyyy-mm-dd'
                });
    });
        initTable();

数据.jsp

<%@ include file="connect.jsp" %>
[
<%  
    Integer ix = 0;
    Rs =st.executeQuery("select * from MsFormulir");
        while(Rs.next())
          { 
            ix++;
        %>
    {
        "ix"            : "<%=ix %>",
        "no_form": "<%=Rs.getString("NoFormulir")==null?"":Rs.getString("NoFormulir").trim() %><input type=\"hidden\" value=\"<%=Rs.getString("NoFormulir")==null?"":Rs.getString("NoFormulir") %>\" name=\"my_form\" id=\"my_form_<%=ix %>\">",
        "tgl_setor": "<%=Rs.getString("TglSetor")==null?"":Rs.getString("TglSetor").trim() %>"
    }
    <% 
        if(Rs.isLast()==false)
        {
    %>      
            ,
    <%  } %>

    <% } %>
]

最佳答案

这是因为 Bootstrap Table 会在您每次更改页面时重新呈现您的表格。所以在每一页上,日期选择器输入都被替换了。 您应该在 page-change.bs.table 事件回调中初始化日期选择器。

$table.on('page-change.bs.table', function (d)
    {
            $('.datepicker').DatePicker({
                    orientation: "top",
                    autoclose: true,
                    todayHighlight: true,
                    format: 'yyyy-mm-dd'
                });
});

关于javascript - 单击分页 Bootstrap 表时不显示日期选择器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41159390/

相关文章:

javascript - html2canvas() 中的屏幕截图是在哪里制作的?

php - 通过 Ajax 直接访问服务器数据库(无需 PHP 或其他中间件)

javascript - 禁用基于第一个日期选择器字段中选择的日期的日期

javascript - 将内联 jquery datepicker 与输入字段结合起来?

javascript - 如何克隆 Vuex 数组?

javascript - 根据嵌套键值对对象数组进行排序的最快方法

javascript - Angular.js 工作在一个元素上,但工作在一个非常相似的元素上

javascript - 如何使用 jQuery 替换 Textarea 中的 href 链接

javascript - 为什么这个组件根本不显示? react 日期选择器

jquery - 如何使用 jQuery 在 HTML 元素旁边获取纯文本?