jquerybootstrap-table

bootstrap-table-filter-control options sorting


Using Boostrap table by whenzhixin with filter-control extension. http://bootstrap-table.wenzhixin.net.cn/extensions/#table-filter-control

I would like the options display in the select to be sorted in numerical order.

Code is available at: https://jsfiddle.net/yd75psoc/4

<script type="text/javascript" src="https://unpkg.com/jquery@3.3.1/dist/jquery.min.js"></script>

<script src="https://unpkg.com/bootstrap-table@1.14.2/dist/bootstrap-table.min.js"></script>
<script src="https://unpkg.com/bootstrap-table@1.14.2/dist/extensions/filter-control/bootstrap-table-filter-control.min.js"></script>

<table
    id="table"
    data-filter-control="true"
    data-filter-show-clear="true">
    <thead>
        <tr>
            <th data-field="id">ID</th>
            <th data-field="name">Item Name</th>
            <th data-field="price" data-filter-control="select">Item Price</th>
        </tr>
    </thead>
</table>

<script>
    var $table = $('#table')

    $(function() {
        var data = [
            {
                'id': 0,
                'name': 'Item 0',
                'price': '$10'
            },
            {
                'id': 1,
                'name': 'Item 1',
                'price': '$1'
            },
            {
                'id': 2,
                'name': 'Item 2',
                'price': '$2'
            }
        ]
        $table.bootstrapTable({data: data})
    })
</script>

You will see that options are shown in the following order: 1, 10, 2. current behaviour

I need these values to be displayed in numerical order: 1, 2, 10.


Solution

  • It's a bug in the filter-control version you are using.

    I have edited you code and it's working with the filter-control version that i'm using.

    edited fiddle: https://jsfiddle.net/eitanmg/0y3tp4n7/1/

    filter-control version that i'm using (and solved you problem):

    https://raw.githubusercontent.com/eitanmg/bootstrap-table-filter-control/master/bootstrap-table-filter-control.js

    just replace this library with yours and you should be fine.