locked
Jquery data table problem RRS feed

  • Question

  • User671453965 posted

    I download a jquery datatables sample source code from internet, From the source code, I didn't found where to pass the parameters(iDisplayLength,sSortDir_0iSortCol_0) in aspx file. I just notice these parameters can get from handler file. Can explain it. Thanks. 

    ASPX:
    $(document).ready(function () {
                tReportByMember = $("#tblReport").dataTable({
                    bFilter: false,
                    "bLengthChange": false,
                    "bProcessing": true,
                    "bServerSide": true,
                    "iDisplayLength": 10,
                    "sDom": 'prtp',
                    "sAjaxSource": "ReportHandler.ashx",
                    "fnServerData": function (sSource, aoData, fnCallback) {
    
                        var startDate = GetDateFrom();
                        var endDate = GetDateTo();
    
                        aoData.push({ "name": 'startDate', "value": startDate },
                                    { "name": 'endDate', "value": endDate }
                            );
    
                        $.ajax({
                            "dataType": 'json',
                            "contentType": "application/json; charset=utf-8",
                            "type": "GET",
                            "url": sSource,
                            "data": aoData,
                            "success": function (msg) {
                                var resultTable = $("#tblReport").dataTable();
                                resultTable.show();
                            }
                        });
                    })
    ASHX:
     public class JQueryDataTable
            {
                public int displayLength { get; set; }
                public string sort { get; set; }
                public int sortCol { get; set; }
    
                public void getRequest(HttpContext context)
                {
                    this.displayLength = int.Parse(context.Request.Params["iDisplayLength"]);
                    this.sort = (context.Request.Params["sSortDir_0"] ?? "desc").ToString();
                    this.sortCol = int.Parse(context.Request.Params["iSortCol_0"] ?? (Byte.MinValue).ToString());
                }
            }

    Wednesday, June 8, 2016 6:17 AM

Answers

  • User1724605321 posted

    Hi ckcheah,

    Yes , DataTables will send a number of variables to the server to allow it to perform the required processing ,for example , iDisplayLength,iSortingCols .... .They are sent to server automatically .

    Best Regards,

    Nan Yu

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, June 10, 2016 3:16 AM

All replies

  • User1724605321 posted

    Hi ckcheah ,

    The parameters like iDisplayLength are sent to the server for each draw request. Your server-side script must use this information to obtain the data required for the draw. For example , "iDisplayLength" is number of rows to display on a single page when using pagination. If feature enabled (bLengthChange) then the end user will be able to override this to a custom setting using a pop-up menu.  So number of records returned from server side will be equal to this number, unless the server has fewer records to return.

    You could refer to below link for details :

    http://legacy.datatables.net/ref 

    https://datatables.net/release-datatables/examples/data_sources/ajax.html 

    Best Regards,

    Nan Yu

    Wednesday, June 8, 2016 8:03 AM
  • User671453965 posted

    Hi ckcheah ,

    The parameters like iDisplayLength are sent to the server for each draw request. Your server-side script must use this information to obtain the data required for the draw. For example , "iDisplayLength" is number of rows to display on a single page when using pagination. If feature enabled (bLengthChange) then the end user will be able to override this to a custom setting using a pop-up menu.  So number of records returned from server side will be equal to this number, unless the server has fewer records to return.

    You could refer to below link for details :

    http://legacy.datatables.net/ref 

    https://datatables.net/release-datatables/examples/data_sources/ajax.html 

    Best Regards,

    Nan Yu

    Thanks. But I didn't see where to pass this parameter from aspx file or this pass automatic by system?

    Wednesday, June 8, 2016 8:36 AM
  • User1724605321 posted

    Hi ckcheah,

    Yes , DataTables will send a number of variables to the server to allow it to perform the required processing ,for example , iDisplayLength,iSortingCols .... .They are sent to server automatically .

    Best Regards,

    Nan Yu

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, June 10, 2016 3:16 AM