admin管理员组

文章数量:1296505

I have a code that I am trying to understand, from another developer. He is using datatable.js, something like:

function initservicesDataTable(){

    DataTable.datetime('DD/MM/YYYY');

    let config = {

        order: [[3, 'asc']],
        columns: [
            { orderable: false, width: '10%' }
            // more columns
        ],

        fixedColumns: {
            left: 1,
        },
        fixedHeader: {
            header: false,
            footer: true
        },
        initComplete: function () {
            // add embedded filters
            this.api()
                .columns()
                .every(function () {
                    let column = this;
                    let title = column.footer().textContent;

                    // More code

                });
        }

    };
    
    return new DataTable('.dt-services', $.extend({}, config, GetDatatableConfig()));
}

He then has an action (Index) inside the Home Controller where he fills up the model and use to create the table:

public IActionResult Index()
{ // call all the data from the context, as of View(Model). No pagination applied }

The View is as below:

<div class="datatable table-responsive shadow-sm mt-3 mb-3">
    <table class="table table-striped table-hover dt-services">
        <thead>
            <tr>
                <th scope="col" class="text-center">Name</th>
            </tr>
        </thead>
        <tbody>
                        
            @foreach (Service service in Model)
            {
                <tr>
                    <td class="dt-left">
                        @service.Name
                    </td>
                </tr>
            }
        </tbody>
        <tfoot>
            <tr>
                <th>Name</th>
            </tr>
        </tfoot>
    </table>
</div>

I have been trying to apply pagination, but I could not, in the index nothing is paginated, all the data is returned, and I cannot paginate, could anyone shed a light on how I could applomplish this? I tried multiple exampled and none worked.

本文标签: javascriptPagination with Datatablejs and aspnet mvcStack Overflow