How to Create a DataTable with Sequential Display IDs in Ascending Order

In this blog post, you can discuss the need for displaying data with sequential IDs in ascending order, such as in scenarios where you want to maintain a clean and organized data presentation. The blog can then provide a step-by-step guide on how to achieve this using DataTables in web development, with a focus on the JavaScript code modifications required. You can include code examples and explanations to make it easy for readers to implement this feature in their own projects.

Html Part:-

<div class="card mt-2">
                                        <div class="card-body shadow ">

                                            <!-- Table for showing data start -->
                                            <table id="organisation_data_Table" class="table" data-order='[[ 0, "asc" ]]'>
                                                <thead>

                                                </thead>
                                                <tbody>

                                                </tbody>
                                            </table>
                                            <!-- Table for showing data end -->
                                        </div>
                                    </div>

Javascript Code:-

 $(document).ready(function() {
        // image load
        window.addEventListener("load", function() {
            $(".loader").delay(500).fadeOut("slow");
        });
        var slug_id = $('#org_user_id').val();


        var dt = $('#organisation_data_Table').DataTable({
            "ajax": {
                "paging": true,
                "scrollX": true,
                "lengthChange": true,
                "searching": true,
                "ordering": true,
                "processing": true,
                "serverSide": true,
                "url": "{{url('api/v1/j/organization/index')}}/" + slug_id,
                "dataSrc": 'data',
                "type": "GET",
                "datatype": "json",
                "crossDomain": true,
                "beforeSend": function(xhr) {
                    xhr.setRequestHeader("Authorization", "Bearer " + localStorage.getItem(
                        'a_u_a_b_t'));
                }
            },
            processing: true,
            language: {
                processing: "<img src='../../assets/images/loader.gif' style='z-index:1071;background-color:white;border-radius:8pt;padding-top:4pt;padding-bottom:4pt;position:fixed;top:0;right:0;bottom:0;left:0;margin:auto;'>"
            },
            rowReorder: {
                selector: 'td:nth-child(2)'
            },
            responsive: true,
            rowReorder: false,
            columnDefs: [{
                    "title": "ID",
                    "targets": 0,
                    "width": "5%"
                },
                {
                    "title": "Organization Name",
                    "targets": 1,
                    "width": "30%"
                },
                {
                    "title": "Dashboard Access",
                    "targets": 2,
                    "width": "30%"
                },

                {
                    "title": "Action",
                    "targets": 1,
                    "width": "25%"
                },
            ],
            columns: [{
                    
                    data: null,
                    render: function(data, type, row, meta) {
                        return meta.row + 1; 
                    },
                },
                {
                    data: 'org_name'
                },

                // {
                // data: null,
                // render: function(data, type, row)   
                // {
                //     return '<div class="row"><div class="col-2"><button type="button"  id="' +
                //             data['org_slug'] +
                //             '" class="onslugbutton btn btn-primary"><i class="mdi mdi-lead-pencil"></i>Continue to dashbaord </button></div> </div>'

                // },
                // },
                {
                    data: null,
                    render: function(data, type, row) {
                        return '<a href="orgs/' + data['org_slug'] + '/dashboard' + ' " class="btn waves-effect waves-light btn-xs btn-info">Continue Dashboard </a>'

                    },
                },
                {
                    data: null,
                    render: function(data, type, row) {
                        return '<div class="row"><div class="col-2"><button type="button"  id="' +
                            data['id'] +
                            '" class="edit btn btn-primary"><i class="mdi mdi-lead-pencil"></i></button></div><div class="col-2"><button type="button" id="' +
                            data['id'] +
                            '"  class="btn btn-danger delete"><i class="mdi mdi-delete"></i></button></div> </div>'
                    },
                },
            ],
        });

Add 1 to meta.row (which starts from 0) for the display ID

 data: null,
                    render: function(data, type, row, meta) {
                        return meta.row + 1; 

I hope this will help you….!!!!

Related Posts

Exploring Financial Operations Workflows in Modern Cloud Environments

Introduction The Certified FinOps Professional is the definitive benchmark for experts looking to master the intersection of finance, engineering, and business. As organizations transition from traditional data…

Read More

Strategic Certified FinOps Engineer integrates governance with cloud operations

Introduction The shift to cloud computing has fundamentally altered how businesses manage infrastructure, but it has also introduced significant financial complexities that many engineering teams struggle to…

Read More

Certified FinOps Manager Knowledge for Cloud Financial Governance

Introduction The shift toward cloud-native infrastructure has brought undeniable speed, but it has also introduced significant financial complexity. The Certified FinOps Manager is a professional designation designed…

Read More

Smart Career Growth Through Certified FinOps Architect Learning Journey

Introduction The Certified FinOps Architect is a professional certification designed to help engineers, cloud professionals, and managers optimize cloud financial operations and cost efficiency. This guide is…

Read More

CDOM – Certified DataOps Manager Learning Path for Modern Data Professionals

Introduction The CDOM – Certified DataOps Manager is a professional designation designed to bridge the gap between data engineering and operational excellence. This guide is written for…

Read More

Professional development journey using CDOA – Certified DataOps Architect

Introduction The CDOA – Certified DataOps Architect is a professional designation designed to address the unique challenges of managing and scaling data delivery in cloud-native environments. This…

Read More
Subscribe
Notify of
guest
0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x