How to pass parameters if server side processing is true?

How to pass parameters if server side processing is true?

HoneydewHoneydew Posts: 25Questions: 7Answers: 0

The html code I have written so far is:

    $(document).ready(function () {
        $.ajax({
            "url": "Handlers/jQueryDatatableHandler.ashx",
            "data": { Operation: 'EmployeeList', searchText: '' },
            success: function (data) {
                json = JSON.parse(data);
                columns = [];
                // build column titles
                for (var i = 0; i < json.colnames.length; i++) {
                    columns.push({ title: json.colnames[i] });
                }

                var table = $('#example').DataTable({
                    "responsive": true,
                    "processing": true, 
                    "serverSide": true,
                    "order": [[4, 'desc']],
                    data: json.rows,
                    columns: columns,
                    columnDefs: [
                        {
                            targets: 0,                           
                            render: function (data, type, row) {
                                if (type === 'display') {
                                    return '<input type="checkbox" class="editor-active">';
                                }
                                return data;
                            },
                            className: "dt-body-center",
                            "orderable": false,
                            "searchable": false
                        },
                        {
                            targets: 1,
                            visible: false
                        },
                        {
                            targets: -1,
                            visible: false
                        }
                    ]
                });
            }
        });

jQueryDatatableHandler.ashx code

  public class DatatableInboxResults
  {
    public int draw { get; set; }
    public int recordsTotal { get; set; }
    public int recordsFiltered { get; set; }
    public List<string> colnames;
    public List<string[]> rows { get; set; }
  }

private string BuildDatatableResults()
{
    EmployeeListParameters mlp = new EmployeeListParameters();       
    mlp.numberOfRows = rowsCount; //not sure how to pass this value
    mlp.pageIndex = pageIndex; //not sure how to pass this value
    mlp.sortColumnName = sortColumnName; //not sure how to pass this value
    mlp.sortOrderBy = sortOrderBy; //not sure how to pass this value       
    mlp.searchText = searchTxt;

    DatatableInboxResults result = new DatatableInboxResults();
    result.colnames = new List<string>();

    result.colnames.Add(" ");
    result.colnames.Add("EmployeeId");
    result.colnames.Add("Name");
    result.colnames.Add("Title");
    result.colnames.Add("Joining");
    result.colnames.Add("Viewed");

    int totalRecords;
    int colCount = result.colnames.Count;;
    List<string> rows = new List<string>();
    result.rows = new List<string[]>();
    EmployeeViewerDataProvider mvdp = new EmployeeViewerDataProvider ();
    List<NEmployee> empList;
    msgList = mvdp.GetEmployeeDetails(mlp, out totalRecords);

    foreach (NEmployee msg in empList)
    {
        string[] row = new string[colCount];

        row[0] = "0";
        row[1] = msg.EmployeeId.ToString();
        row[2] = msg.Name;
        row[3] = msg.Title;
        row[4] = TimeZoneInfo.ConvertTimeFromUtc(msg.TimeSent, tinfo).ToString();
        row[5] = msg.Viewed.ToString();

        result.rows.Add(row);
    }
    result.recordsTotal = (Convert.ToInt32(totalRecords) + Convert.ToInt32(mlp.numberOfRows) - 1) / Convert.ToInt32(mlp.numberOfRows);

    return new JavaScriptSerializer().Serialize(result);
}

This is working fine if I set serverside processing to false but when I make it true there are certain errors. Can someone please help me or suggest how to pass/send parameters in the code so it works fine.

Please advise how to do this.

This question has an accepted answers - jump to answer

Answers

This discussion has been closed.