附加;为了按组显示数据,每组以 1 个数字开始

发布于 2025-01-11 05:19:53 字数 3480 浏览 0 评论 0原文

我很困惑如何正确呈现数据表。 我的html代码是

<table id="EmployeeGrid" class="table table-bordered table-striped">
                        <thead>
                        <tr>
                            <th colspan="6"><i class="fas fa-user"></i> Employee Info</th>
                            <th colspan="5"><i class="fas fa-file"></i> Contract Info</th>
                            
                        </tr>
                        <tr>

                            <th>IR No.</th>
                            <th>Name</th>
                            <th>Job Title</th>
                            <th>NIC</th>
                            <th>Location</th>
                            <th>Project</th>

                            <th>DOJ</th>
                            <th>Status</th>
                            <th>St. Date</th>
                            <th>End Date</th>
                            <th>Type</th>

                        </tr>
                        </thead>
                        <tbody>
                            <tr><th colspan="12"></th></tr>
                        </tbody>
                    </table>

在html预定义标题中。相当于通过 jQuery 渲染。

我的 jQuery 代码

var DataGrid = $('#EmployeeGrid');
        var url = "{{url('employees/search')}}";
        var dataTable = DataGrid.DataTable({
            dom: "Tlfrtip",
            aaSorting: [], //disabled initial sorting
            ajax: url,
            paging: true,
            searching: false,
            info: true,
            autoWidth: false,
            responsive: true,
            processing: true,
            serverSide: true,
            ordering: true,
            lengthMenu: [[10,25, 50, 100, 200, 500, 1000], [10,25, 50, 100, 200, 500, 1000]],
            pageLength: 10,
            LengthChange: false,
            "scrollX": true,


            /*"columnDefs": [
             {"width": "10%", "targets": 4, "class":'word-wrap'},
             ],*/

            columns: [
                //Table Column Header Collection

                {data: "irp_number"},
                {
                    data: null, render: function (data, type, row) {
                    var url_edit = "{{url('employees/edit_view')}}";

                    return '<a href="'+url_edit+'/'+data.employee_id+'" data-id="'+data.employee_id+'" data-toggle="tooltip" data-placement="bottom" title="Edit & View Employee">'+data.employee_name+'</a>'

                }
                },
                {data: "empDesignation"},
                {data: "cnic"},
                {data: "empDutyStation"},
                {data: "empGender"},

                {data: "empIRJoiningDate"},
                {data: "empStatus"},
                {data: "empIRJoiningDate"},
                {data: "empIRJoiningDate"},
                {data: "employment_type"}


            ],

        });

非常完美。

我的问题是如何追加新部门:data.depName 因为我想按它和 1,2,3...n 的 strat 系列进行分组。下一组 1,2,3...n 就像这样如图所示: https://datatables.net/examples/advanced_init/row_grouping.html

I am confuse how to render data table properly.
my html code is

<table id="EmployeeGrid" class="table table-bordered table-striped">
                        <thead>
                        <tr>
                            <th colspan="6"><i class="fas fa-user"></i> Employee Info</th>
                            <th colspan="5"><i class="fas fa-file"></i> Contract Info</th>
                            
                        </tr>
                        <tr>

                            <th>IR No.</th>
                            <th>Name</th>
                            <th>Job Title</th>
                            <th>NIC</th>
                            <th>Location</th>
                            <th>Project</th>

                            <th>DOJ</th>
                            <th>Status</th>
                            <th>St. Date</th>
                            <th>End Date</th>
                            <th>Type</th>

                        </tr>
                        </thead>
                        <tbody>
                            <tr><th colspan="12"></th></tr>
                        </tbody>
                    </table>

In html pre define header. equivalent to which is rendering by jQuery.

My jQuery code is

var DataGrid = $('#EmployeeGrid');
        var url = "{{url('employees/search')}}";
        var dataTable = DataGrid.DataTable({
            dom: "Tlfrtip",
            aaSorting: [], //disabled initial sorting
            ajax: url,
            paging: true,
            searching: false,
            info: true,
            autoWidth: false,
            responsive: true,
            processing: true,
            serverSide: true,
            ordering: true,
            lengthMenu: [[10,25, 50, 100, 200, 500, 1000], [10,25, 50, 100, 200, 500, 1000]],
            pageLength: 10,
            LengthChange: false,
            "scrollX": true,


            /*"columnDefs": [
             {"width": "10%", "targets": 4, "class":'word-wrap'},
             ],*/

            columns: [
                //Table Column Header Collection

                {data: "irp_number"},
                {
                    data: null, render: function (data, type, row) {
                    var url_edit = "{{url('employees/edit_view')}}";

                    return '<a href="'+url_edit+'/'+data.employee_id+'" data-id="'+data.employee_id+'" data-toggle="tooltip" data-placement="bottom" title="Edit & View Employee">'+data.employee_name+'</a>'

                }
                },
                {data: "empDesignation"},
                {data: "cnic"},
                {data: "empDutyStation"},
                {data: "empGender"},

                {data: "empIRJoiningDate"},
                {data: "empStatus"},
                {data: "empIRJoiningDate"},
                {data: "empIRJoiningDate"},
                {data: "employment_type"}


            ],

        });

this works perfect.

My Question is how to append new Dept : data.depName
as i want to group by it and strat series from 1,2,3...n. next group 1,2,3...n

like this as shown in figure:
https://datatables.net/examples/advanced_init/row_grouping.html

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文