wenzhixin bootstrap-table unable to click on select2

扶醉桌前 提交于 2019-12-13 02:15:12

问题


Here is the problem, and a put together a mockup in Codeply http://www.codeply.com/go/rxWzeVwBUa.

I am unable to click on the Select2 dropdown box withing the datatable. Any help would be appreciated.

    <div class="container">
        <h1>From data</h1>
        <p></p>
        <table id="table">
            <thead>
            <tr>
                <th data-field="id">ID</th>
                <th data-field="name">Item Name
                    <select class='table finditem'>
                        <option></option>
                        <option value='0'>Item 0</option>
                        ...
                    </select>
                </th>
                <th data-field="price">Item Price</th>
            </tr>
            </thead>
        </table>
    </div>

        $table.bootstrapTable({
            data: data});
        });


        $('#finditem').select2({
            placeholder: 'Find Item',
            allowClear: true
        });

回答1:


I posted this to the developer on github and the developer posted the solution;

https://github.com/wenzhixin/bootstrap-table/issues/1254#issuecomment-130358202 http://www.codeply.com/go/e4LJoKfhdR

$table.on('post-header.bs.table', function () {
    $('.finditem').select2({
        placeholder: 'Find Item',
        allowClear: true
    });
});

Incidentally I found out if you want to use any select2 event listeners they also have to be placed within this function also. I use a series of cascading select2 boxes to automatically update the table when they selected.

    $table.on('post-header.bs.table', function () {
        $('.finditem').select2({
            placeholder: 'Find Item',
            allowClear: true
        });
        $('.finditem').on('select2:close', function(){
            $table.bootstrapTable('refresh');
        });
    });


来源:https://stackoverflow.com/questions/31949354/wenzhixin-bootstrap-table-unable-to-click-on-select2

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!