C# ServerSide not working

C# ServerSide not working

AddupAddup Posts: 11Questions: 5Answers: 0
edited December 2018 in Free community support

I have created an api but it loads all the data and ignore serverside:true, please help?

$(document).ready(function () {
$.ajax({
"dataType": "application/json",
"type": "GET",
"url": "http://localhost:54888/api/order",
"success": function (dataStr) {
console.log(dataStr.responseText);
// laod Data to DataTable Jquery
var resp = jQuery.parseJSON(dataStr.responseText ? dataStr.responseText : dataStr);
$('#example').DataTable({
data: resp["rows"],
columns: resp["aoColumns"],
scrollX: true,
autoWidth: true,
bScrollCollapse: true,
// paging: true,
// retrieve: true,
"jQueryUI": true,
/serverSide: true,
processing:true

                });
            },
            "error": function (dataStr) {
                //console.log(dataStr);
                var resp = jQuery.parseJSON(dataStr.responseText ? dataStr.responseText : dataStr);
                $('#example').DataTable({

                    data: resp["rows"],
                    columns: resp["aoColumns"],
                    scrollX: true,
                    autoWidth: true,
                    bScrollCollapse: true,
                    //paging: true,
                    //retrieve: true,
                    "jQueryUI": true,
                    serverSide: true,
                    processing: true
                });

            }
        })
    });

Answers

  • kthorngrenkthorngren Posts: 21,303Questions: 26Answers: 4,947

    Does your server script support the communications protocol described here:
    https://datatables.net/manual/server-side

    Your server script is responsible for returning the correct rows.

    Kevin

  • AddupAddup Posts: 11Questions: 5Answers: 0

    Yes, Here is my server Script

    using (var db = new Database(settings.DbType, settings.DbConnection))
    {
    var response = new Editor(db, "tbl_Order")
    .Model<orders>()
    .Field(new Field("Reference")
    // .Validator(Validation.NotEmpty())
    )
    .Field(new Field("Comments")
    //.Validator(Validation.NotEmpty())
    )
    .Process(request)
    .Data();

                // Prepare List of Sql Parameter
                DataTable dataTableData = GetDataTableFromStoreProcedure(@"[dbo].[proc_Order_Get]");
    
    
                // Convert Data table to Json for Datatabe in jquery
                // Separet column and row so you can directly add 
                List<AoColumns> aoColumn = new List<AoColumns>();
                for (int i = 0; i < dataTableData.Columns.Count; i++)
                {
                    aoColumn.Add(
                        new AoColumns { bSortable = true, title = dataTableData.Columns[i].ColumnName.ToString() });   
                }
                List<List<string>> rows = new List<List<string>>();
                for (int index = 0; index < dataTableData.Rows.Count; index++)
                {
                    DataRow dataRows = dataTableData.Rows[index];
                    List<string> Row = new List<string>();
    
                    for (int j = 0; j < dataRows.ItemArray.Length; j++)
                    {
                        Row.Add(dataRows.ItemArray[j].ToString());
                    }
    
                    rows.Add(Row);
                }
                var data = new   Data { aoColumns = aoColumn, rows = rows };
                return Json(data);
            }
    
  • kthorngrenkthorngren Posts: 21,303Questions: 26Answers: 4,947

    Its unclear to me from that code what your SQL query is doing. Does your SQL query use limit, offset and order by to perform a query that only returns the rows for the page being displayed?

    Kevin

  • AddupAddup Posts: 11Questions: 5Answers: 0

    Thank you for your reply,
    the SQl query is a stored proc, its just link up a few tables and return a select
    Regards,
    Yosh

This discussion has been closed.