ServerPaging With Razor

6 posts, 0 answers
  1. Timothy J
    Timothy J avatar
    1 posts
    Member since:
    Sep 2014

    Posted 07 Oct 2019 Link to this post

    I am trying to do ServerPaging with this example from telerik:  https://github.com/telerik/ui-for-aspnet-core-examples/tree/master/grid/razor-pages-custom-datasource-date-editing/RazorPageGridTest/Pages/Customer

     

    I have modified OnPostReadRecords by adding [DataSourceRequest] DataSourceRequest request

    public JsonResult OnPostReadRecords([DataSourceRequest] DataSourceRequest request)

    And I have added .ServerPaging(true) to the grid definition.

    The resulting value of request is default and the page number is always '1'.

    I am new to the telerik controls, so it's really like casting spells for me.

  2. Tsvetomir
    Admin
    Tsvetomir avatar
    790 posts

    Posted 10 Oct 2019 Link to this post

    Hi Timothy,

    The project that you refer to uses a custom data source. When using the custom data soure all of the options are left for the developer to set. Therefore, you would have to handle the parameterMap for each of the CRUD operations. 

    However, I would recommend taking a predefined schema and parameter map by setting the type of the data source:

                .DataSource(d =>
                    d.Custom()
                    .Type("aspnetmvc-ajax")
                    .ServerPaging(true)
                    .ServerFiltering(true)
                    .ServerSorting(true)
                    .Transport(t =>
                    {
                        t.Read(r => r.Action("Customer", "Index", new { handler = "ReadRecords" }).Type(HttpVerbs.Post));
                        t.Update(r => r.Action("Customer", "Index", new { handler = "UpdateRecord" }).Type(HttpVerbs.Post));
                        t.ParameterMap("parameterMap");
                    })
                    .Schema(s => s.Model(m =>
                    {
                        m.Id(i => i.CustomerId);
                        m.Field("ClockOut", typeof(DateTime?));
                    }).Total("Total").Data("Data"))
                )

    As well as, you would have to indicate which fields from the response are holding the data of the grid and the number of items. Namely, the Data and Total options.

    Lastly, on the server-side, you would have to create a DataSourceResult object. Or you can use the following method:

            public JsonResult OnPostReadRecords([DataSourceRequest] DataSourceRequest request)
            {
                List<RazorPageGridTest.Customer> data = new List<RazorPageGridTest.Customer>();
    
                for (int i = 1; i <= 100; i++)
                {
                    data.Add(new RazorPageGridTest.Customer()
                    {
                        CustomerId = i,
                        Name = "Name "+ i.ToString(),
                        Address = "Address " + i.ToString(),
                        ClockOut = DateTime.Now.AddHours(i)
                    });
                }
                
                return new JsonResult(data.ToDataSourceResult(request));
            }

    In case you would like to have just an ajax-bound grid, I would recommend taking a look at the example below which uses the predefined Ajax() data source:

    https://github.com/telerik/ui-for-aspnet-core-examples/tree/master/grid/razor-pages-crud

    Let me know in case further assistance is required.

     

    Best regards,
    Tsvetomir
    Progress Telerik

    Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
  3. Peter Huisman
    Peter Huisman avatar
    19 posts
    Member since:
    Dec 2004

    Posted 12 Dec 2019 in reply to Tsvetomir Link to this post

    Could you please not remove examples so quickly. The average help is already so limited.
  4. Tsvetomir
    Admin
    Tsvetomir avatar
    790 posts

    Posted 12 Dec 2019 Link to this post

    Hi Peter,

    The examples for the ASP.NET Core wrappers were merged into a single project. Currently, not all of the links have been correctly updated. The link for the specific example could be found here:

    https://github.com/telerik/ui-for-aspnet-core-examples/tree/master/Kendo.Examples.RazorPages/Kendo.Examples.RazorPages/Pages/Grid

    Feel free to contact me back in case further assistance is required.

     

    Best regards,
    Tsvetomir
    Progress Telerik

    Get quickly onboarded and successful with Telerik UI for ASP.NET Core with the dedicated Virtual Classroom technical training, available to all active customers.
  5. Peter Huisman
    Peter Huisman avatar
    19 posts
    Member since:
    Dec 2004

    Posted 09 Mar 2020 in reply to Tsvetomir Link to this post

    And also this one is quickly removed... 
  6. Viktor Tachev
    Admin
    Viktor Tachev avatar
    2499 posts

    Posted 12 Mar 2020 Link to this post

    Hello Peter,

     

    You can find the updated link to the examples below:

    https://github.com/telerik/ui-for-aspnet-core-examples/tree/master/Telerik.Examples.RazorPages/Telerik.Examples.RazorPages/Pages/Grid

     

    Regards,
    Viktor Tachev
    Progress Telerik

    Get quickly onboarded and successful with Telerik UI for ASP.NET Core with the dedicated Virtual Classroom technical training, available to all active customers.
Back to Top