Jquery Bootstrap数据表排序无法正常工作

时间:2016-09-06 05:59:39

标签: jquery twitter-bootstrap

@app.route('/test/api/v1.0/docs_page2', methods=['POST'])
 def search_docs_page2():
     if 'id' in session:
         docs = []
         no_of_pgs = 0
         doc_list = common_search_code()
         header_dict = dict(request.headers)
         for i in header_dict.items():
             if i == 'Max-Per-Page':
                 max_per_pg = int(header_dict[i])
         no_of_pgs = len(doc_list) / max_per_pg
         print 'number of doc: ' + str(len(doc_list))
         print 'number of pages: ' +  str(no_of_pgs)
         print 'max per page:' + str(max_per_pg)
         page = int(request.form.get('page', type=int, default=1))
         cursor = request.form.get('cursor')
         if cursor:
             print 'hey'
             doc_list.with_cursor(cursor)
             docs = doc_list.fetchmany(4)
             for r in docs:
                 print r, 'rrrr'

         return jsonify({'docs': docs}), 200

     return jsonify({'message': "Unauthorized"}), 401







curl:curl -b cookies.txt  -X POST http://localhost:8081/test/api/v1.0/docs_page2 -H 'max_per_page:4' -H 'Content-type:application/json' -F 'cursor=1'

enter image description here

以上是我的数据表代码,排序无法正常工作。

4 个答案:

答案 0 :(得分:0)

你走了:

$("#tbllistOPDetails").DataTable({
    aaSorting": [],
    "bSorting": false,
    "bProcessing": false,
    "bPaginate": false,
    "bFilter": false,
    "bDestroy": false,
    "bAutoWidth": true,
    "sScrollY": "scrollY", //Put height if you want
    "aoColumns": [
                    { "sTitle": "ID", "sType": 'numeric'  },
                    { "sTitle": "Name" },
                    { "sTitle": "Age", "sType": 'numeric' },
                     |
                     |
                     |
                     |
                     |
                     |
                    { "sTitle": "Preference" }
                ],

    "aaData": DataName
});

您必须告诉数据表有关列类型的信息。所以它会排序正确。

答案 1 :(得分:0)

您可以查看网站https://datatables.net/plug-ins/sorting/上的文档,这很容易实现

    <script type="text/javascript" src="jquery.dataTables.js"></script>
<script type="text/javascript" src="dataTables.numericComma.js"></script>
<script type="text/javascript">
    $(document).ready(function() {
        $('#example').dataTable( {
            "columnDefs": [
                { "type": "numeric-comma", targets: 3 }
            ]
        } );
    } );
</script>

示例https://datatables.net/examples/plug-ins/sorting_manual

答案 2 :(得分:0)

您可以使用此代码。这有助于获得desc年龄顺序。您可以更改为asc订单。

https://datatables.net/examples/basic_init/table_sorting.html

了解更多详情
$("#tbllistOPDetails").DataTable({               
            "order": [[ 2, "desc" ]]
        });

答案 3 :(得分:0)

尝试以下

$("#tbllistOPDetails").DataTable({
    "scrollX": true,
    "paging": true,
    "scrollCollapse": true,
    "searching": false,
    "orderCellsTop": true,
    "info": true,
});

只需从脚本中删除"scrollY": scrollY,

即可