jQuery UI Widgets Forums Grid Grid server side paging from ASP.NET service

This topic contains 2 replies, has 2 voices, and was last updated by  sdalby 11 years, 7 months ago.

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author

  • sdalby
    Member

    Hi,

    I have been trying all day to combine all sorts of examples from your site in order to try to make a jqxGrid that has server side paging from an ASP.NET WebService (not MVCX)

    There is a ‘root’ and a ‘record’ attribute in the data-source that I havent been able to find documentation for, and I dont understand thier purpose.

    Finally I turned to a PHP example because it was easier to understand and I am not sure if I create the return correctly. I cannot make much sense out of that one should read numbers of rows as data[0].TotalRows and and rows as dataadapter.records, but maybe it is due to some dataAdapter transformation.

    But for now it does not make much of a difference, because the server side method is never called.

    PS. How does one set up an errorhandler for the service side invocations?

    My code looks like this:

    function prepareOverviewGrid() {
    source = {
    url: 'EodOverviewWebService.asmx/GetOverviewLines',
    datatype: "json",
    datafields: [
    { name: 'Id' },
    { name: 'TimeToFire' },
    { name: 'SysDate' },
    { name: 'NewDate' },
    { name: 'Status' },
    { name: 'ReasonForExecution' },
    { name: 'ModulesExecuted' }
    ],
    async: false,
    root: 'Rows',
    beforeprocessing: function (data) {
    source.totalrecords = data[0].TotalRows;
    }
    };
    var dataadapter = new $.jqx.dataAdapter(source);
    $("#jqxOverviewGrid").jqxGrid(
    {
    width: 600,
    source: dataadapter,
    theme: theme,
    autoheight: true,
    pageable: true,
    virtualmode: true,
    rendergridrows: function () {
    return dataadapter.records;
    },
    columns: [
    { text: 'Task id', datafield: 'Id', width: 250 },
    { text: 'Execution date', datafield: 'TimeToFire', width: 200 },
    { text: 'System date', datafield: 'SysDate', width: 200 },
    { text: 'New date', datafield: 'NewDate', width: 180 },
    { text: 'Modules executed', datafield: 'ModulesExecuted', width: 100 },
    { text: 'Reason for execution', datafield: 'ReasonForExecution', width: 140 },
    { text: 'Status', datafield: 'Status', width: 140 }
    ]
    });
    }

    And serverside:

        [WebService(Namespace = "http://t24cockpit.default/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [ScriptService]
    public class EodOverviewWebService : System.Web.Services.WebService
    {
    public class EodRow
    {
    public int Id { get; set; }
    public DateTime TimeToFire { get; set; }
    public DateTime? SysDate { get; set; }
    public DateTime? NewDate { get; set; }
    public int Status { get; set; }
    public string ReasonForExecution { get; set; }
    public string ModulesExecuted { get; set; }
    public bool Errors { get; set; }
    public EodRow(int taskId, DateTime timeToFire, DateTime? sysDate, DateTime? newDate, int status, string reasonForExecution, string modulesExecuted, bool errors)
    {
    Id = taskId;
    TimeToFire = timeToFire;
    SysDate = sysDate;
    NewDate = newDate;
    Status = status;
    ReasonForExecution = reasonForExecution;
    ModulesExecuted = modulesExecuted;
    Errors = errors;
    }
    }
    public class EodOverviewResult
    {
    public int TotalRows { get; set; }
    public List<EodRow> Rows { get; set; }
    public EodOverviewResult(List<EodRow> rows, int totalRows)
    {
    Rows = rows;
    TotalRows = totalRows;
    }
    }
    [WebMethod(EnableSession = true)]
    [ScriptMethod(UseHttpGet = true, ResponseFormat = ResponseFormat.Json)]
    public object GetOverviewLines(int pagenum, int pagesize)
    {
    int skip = pagenum*pagesize;
    int take = pagesize;
    string environment = ((TaskEnvironment) HttpContext.Current.Session[WebConstants.SessionTaskEnvironment]).EnvironmentName;
    List<EodDao.EodStatusAndTask> eodStatusAndTaskListForEnvironment = EodDao.GetEodStatusAndTaskListForEnvironment(environment, skip, take);
    int totalCount = skip == -1 ? eodStatusAndTaskListForEnvironment.Count : EodDao.GetEodStatusRelatedTaskCount(environment);
    List<EodRow> eodRowList = new List<EodRow>();
    foreach (EodDao.EodStatusAndTask eodStatusAndTask in eodStatusAndTaskListForEnvironment)
    {
    EodRow eodRow = null;
    if (eodStatusAndTask.EodStatus != null)
    {
    bool anyErrors = EodDao.HasErrors(eodStatusAndTask.EodStatus.Id);
    eodRow = new EodRow(eodStatusAndTask.Task.Id,
    eodStatusAndTask.Task.TimeToFire,
    eodStatusAndTask.EodStatus.SysDate,
    eodStatusAndTask.EodStatus.NewDate,
    eodStatusAndTask.Task.StatusEnum,
    eodStatusAndTask.EodStatus.ReasonForExecution,
    eodStatusAndTask.EodStatus.ModulesExecuted,
    anyErrors);
    }
    else
    {
    eodRow = new EodRow(eodStatusAndTask.Task.Id,
    eodStatusAndTask.Task.TimeToFire,
    null,
    null,
    eodStatusAndTask.Task.StatusEnum,
    null,
    null,
    false);
    }
    eodRowList.Add(eodRow);
    }
    //return new object[] {totalCount, eodRowList};
    return new EodOverviewResult(eodRowList, totalCount);;
    }
    // from a previous attempts
    [WebMethod(EnableSession = true)]
    [ScriptMethod(UseHttpGet = true, ResponseFormat = ResponseFormat.Json)]
    public int GetOverviewCount()
    {
    string environment = ((TaskEnvironment)HttpContext.Current.Session[WebConstants.SessionTaskEnvironment]).EnvironmentName;
    return EodDao.GetEodStatusRelatedTaskCount(environment);
    }
    }

    Peter Stoev
    Keymaster

    Hi sdalby,

    You can find documentation about ‘record’ and ‘root’ in this help topic: jquery-grid-datasources.htm. Help topic about Server Pading in ASP .NET is also available: asp.net-grid-paging.htm.

    Best Regards,
    Peter Stoev

    jQWidgets Team
    http://www.jqwidgets.com


    sdalby
    Member

    Hi

    I started with that example but in order to follow your instructions, I have changed it back.

    I think that I found out what the cause is but dont know how to fix it. Your code make a response with the form:

    GET /Cob/EodOverviewWebService.asmx/GetOverviewLines?pagenum=0&pagesize=10 HTTP/1.1

    And this causes the error:

    Request format is unrecognized for URL unexpectedly ending in '/GetOverviewLines'.

    I think it is the combination of an URL that identifies a method and using get parameters, but since your code stresses that one should use GET and not POSTS, I am a bit lost.

    As mentioned earlier I cannot figure out how to install an errorhandler to this datasource request.

    Here is the new code:

        source = {
    url: 'EodOverviewWebService.asmx/GetOverviewLines',
    contentType: 'application/json; charset=utf-8',
    datatype: "json",
    datafields: [
    { name: 'Id' },
    { name: 'TimeToFire' },
    { name: 'SysDate' },
    { name: 'NewDate' },
    { name: 'Status' },
    { name: 'ReasonForExecution' },
    { name: 'ModulesExecuted' }
    ],
    async: false,
    formatdata: function (data) {
    return { pagenum: data.pagenum, pagesize: data.pagesize };
    }
    };
    $.ajax({
    url: 'EodOverviewWebService.asmx/GetOverviewCount',
    contentType: 'application/json; charset=utf-8',
    async: false,
    error: errorHandler,
    success: function (data) {
    source.totalrecords = data.d;
    }
    });
    var dataadapter = new $.jqx.dataAdapter(source);
    $("#jqxOverviewGrid").jqxGrid(
    {
    width: 600,
    source: dataadapter,
    theme: theme,
    autoheight: true,
    pageable: true,
    virtualmode: true,
    rendergridrows: function () {
    return dataadapter.records;
    },
    columns: [
    { text: 'Task id', datafield: 'Id', width: 250 },
    { text: 'Execution date', datafield: 'TimeToFire', width: 200 },
    { text: 'System date', datafield: 'SysDate', width: 200 },
    { text: 'New date', datafield: 'NewDate', width: 180 },
    { text: 'Modules executed', datafield: 'ModulesExecuted', width: 100 },
    { text: 'Reason for execution', datafield: 'ReasonForExecution', width: 140 },
    { text: 'Status', datafield: 'Status', width: 140 }
    ]
    });

    and server side:

            [WebMethod(EnableSession = true)]
    [ScriptMethod(UseHttpGet = true, ResponseFormat = ResponseFormat.Json)]
    public List<EodRow> GetOverviewLines(int pagenum, int pagesize)
    {
    int skip = pagenum*pagesize;
    int take = pagesize;
    string environment = ((TaskEnvironment) HttpContext.Current.Session[WebConstants.SessionTaskEnvironment]).EnvironmentName;
    List<EodDao.EodStatusAndTask> eodStatusAndTaskListForEnvironment = EodDao.GetEodStatusAndTaskListForEnvironment(environment, skip, take);
    List<EodRow> eodRowList = new List<EodRow>();
    foreach (EodDao.EodStatusAndTask eodStatusAndTask in eodStatusAndTaskListForEnvironment)
    {
    EodRow eodRow = null;
    if (eodStatusAndTask.EodStatus != null)
    {
    bool anyErrors = EodDao.HasErrors(eodStatusAndTask.EodStatus.Id);
    eodRow = new EodRow(eodStatusAndTask.Task.Id,
    eodStatusAndTask.Task.TimeToFire,
    eodStatusAndTask.EodStatus.SysDate,
    eodStatusAndTask.EodStatus.NewDate,
    eodStatusAndTask.Task.StatusEnum,
    eodStatusAndTask.EodStatus.ReasonForExecution,
    eodStatusAndTask.EodStatus.ModulesExecuted,
    anyErrors);
    }
    else
    {
    eodRow = new EodRow(eodStatusAndTask.Task.Id,
    eodStatusAndTask.Task.TimeToFire,
    null,
    null,
    eodStatusAndTask.Task.StatusEnum,
    null,
    null,
    false);
    }
    eodRowList.Add(eodRow);
    }
    return eodRowList;
    }
    [WebMethod(EnableSession = true)]
    [ScriptMethod(UseHttpGet = true, ResponseFormat = ResponseFormat.Json)]
    public int GetOverviewCount()
    {
    string environment = ((TaskEnvironment)HttpContext.Current.Session[WebConstants.SessionTaskEnvironment]).EnvironmentName;
    return EodDao.GetEodStatusRelatedTaskCount(environment);
    }
    • This reply was modified 11 years, 7 months ago by  sdalby.
Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.