DataTable异步获取 实现行点击并跳转


            function getResults(){
                var callResults = $.ajax({
                    url: "/ding/enq/get/processlist",
                    type: "GET",
                    dataType: "json",
                    headers: {
                        Accept: "application/json;odata=verbose"
                    }
                });

                callResults.done(function (data, textStatus, jqXHR){
                    $('#example').DataTable( {
                        "bDestroy": true,
                        "bProcessing": true,
                        "aaData": data.list,
                        "aoColumns": [
                            { "mData": "project_name" },
                            { "mData": "process_status" },
                            { "mData": "need_feedback_time" },
                            { "mData": "real_feedback_time"}
                        ],
                        "language": {
                            "lengthMenu": "每页显示 _MENU_ 条",
                            "paginate": {
                                "first":      "第一页",
                                "last":       "最后一页",
                                "next":       "下一页",
                                "previous":   "上一页"
                            },
                            "emptyTable":     "没有数据",
                            "info":           "显示 _START_ 到 _END_ 共 _TOTAL_ 条数据",
                            "infoEmpty":      "显示 0 到 0 共 0 条数据",
                            "infoPostFix":    "",
                            "thousands":      ",",
                            "loadingRecords": "没有数据",
                            "processing":     "处理中...",
                            "search":         "查找:",
                            "zeroRecords":    "没有匹配的数据",
                            "infoFiltered": "(过滤总件数 _MAX_ 条)"
                        },
                        "ordering": true,
                        "lengthMenu": [ [10, 25, 50, -1], [10, 25, 50, "All"] ],
                        "fnRowCallback": function( nRow, aData, iDisplayIndex ) {
                            $(nRow).on( 'click', function () {
                                // logger.e(JSON.stringify(aData));
                                // logger.e(JSON.stringify(nRow));
                                // logger.e(iDisplayIndex);
                                $(this).toggleClass('selected');
                                let processId=aData.process_id;
                                window.location.href = "result.html?process=" + processId;
                            });
                        }
                    } );
                });

                callResults.fail(function (jqXHR, textStatus, errorThrown){
                    alertDD("表格发生错误: " + jqXHR.responseText);
                });
            }

window.onload = getResults();

你可能感兴趣的:(JavaScript,web前端)