Datatables binding very slow

Datatables binding very slow

CllCll Posts: 1Questions: 1Answers: 0
edited January 2019 in Free community support

Hello ,
I have a problem about Datatables binding.My code is as below.Data is nearly 9,000 rows and get it under 1 sec from my method(Person).But when it binding to table, it takes over 4 sec.Is it normal ,if not anyone have to any advise?

Ps:I tried "deferRender": true but not benefit.

[HttpGet]
        public IHttpActionResult Person(string op = "",string lan="")
        {
            var response =
            from p in Person
            where p.Force == op
            orderby p.Name
            select p;
        
            return Json(response);
        }

@using Resources;

<style>
   
    table.dataTable td:nth-child(7) {
        width: 430px;
        max-width: 430px;
        word-break: break-all;
        white-space: nowrap;
    }
</style>
<div id="B_@ViewBag.DivId">
    <div class="row">
        <table id="@ViewBag.DivId" class="display" style="width:100%">
            <thead>
                <tr>
                    <th>ID</th>
                    <th>@Resource.Name</th>
                </tr>
            </thead>
            <tfoot>

            </tfoot>
        </table>       
    </div>
</div>

<script type="text/javascript">
    $(document).ready(function () {
        var table = $("#@ViewBag.DivId").DataTable({
            "ajax": {
                "url": "/api/list/Person?op=" + '@ViewBag.Qs["op"]',
                "dataSrc": ""
            },            
            dom: '<"toolbar">' + '<"top">frt<"bottom"lpi><"clear">',                      
            
            "columns": [
               { "data": "ID" },
               { "data": "Name" },
               
               {
                    "data": null,
                    "className": "center",
                    "defaultContent": '<button type="button" class="btn btn-info click_it" style="margin-top: -6px;margin-bottom: -5px;width: -webkit-fill-available;">@Resource.Show</button>'
               }
            ],
            "columnDefs": [
                {
                "targets": [0],
                "visible": false,
                    "searchable": false
                } 
            ]
        });

        $('#@ViewBag.DivId').on('click', 'tr', function (evt) {         

            var rowData = table.row(this).data();
            if (rowData && rowData.ID) {
                var url = "/Detaail/Person/" + rowData.ID;
                window.location.href = url;
            }
        });
    
        Refresh = function () {
            table.ajax.reload();
        }

    });
</script>

Answers

  • colincolin Posts: 15,240Questions: 1Answers: 2,599

    Hi @Cll ,

    This section of FAQ discusses speeds - I'd suggest going through those options first and see if you can get the performance that you want.

    Cheers,

    Colin

This discussion has been closed.