Kendo grid does not bind data on datasoruce bind but binds on page refresh

5 posts, 0 answers
  1. Naga
    Naga avatar
    3 posts
    Member since:
    Jul 2020

    Posted 03 Jul 2020 Link to this post

         I have implemented a simple Kendo grid in ASP .Net Core which should bind the data on DataSoruce Read request. In actual it is not binding data in read request but binds the data whenever i click on 'refresh' icon under pagination. Below is my code - 

     

    <div class="grid-container">

            @(Html.Kendo().Grid<CAMPv2.Models.AutoPoco.Role>()
        .Name("RolesGrid")
        .Columns(columns =>
        {
            columns.Bound(c => c.Name);
            columns.Bound(c => c.NormalizedName);
            columns.Bound(c => c.Description);
            columns.Bound(c => c.Status);
        })    
        .Scrollable()
        .Sortable()
        .Pageable(pageable => pageable
        .Refresh(true)
        .PageSizes(true)
        .ButtonCount(5))
        .DataSource(datasource => datasource
        .Ajax()
        .Read(read => read.Action("GetRoles", "Role"))

        )
        )
        </div>

     

    Below is code behind - 

    [HttpPost]
            public IActionResult GetRoles([DataSourceRequest] DataSourceRequest request)
            {
                List<Role> _lrolePermissionDetails = _tableOperations.GetAll<Role>(ApplicationConstants.CONNECTOR_AUTOPOCOAUTH, "Role", _loggingService).ToList();
                return Json(_lrolePermissionDetails.ToDataSourceResult(request));           
            }

     

    Please let me know what i am missing here.

    Thanks,

    Naga

     

     

  2. Naga
    Naga avatar
    3 posts
    Member since:
    Jul 2020

    Posted 03 Jul 2020 in reply to Naga Link to this post

    I have also added below scripts in _Layout page - 
    <script src="~/lib/Kendo-UI/js/kendo.all.min.js"></script>
    <script src="~/lib/Kendo-UI/js/kendo.aspnetmvc.min.js"></script>

    Startup.cs has below code as well - 
    services.AddMvc().AddJsonOptions(options =>

    {
          options.SerializerSettings.ContractResolver = new DefaultContractResolver();
     });
    services.AddKendo();


  3. Nikolay
    Admin
    Nikolay  avatar
    302 posts

    Posted 08 Jul 2020 Link to this post

    Hello Naga,

    Thank you for sharing the Grid declaration.

    If the Grid binds to the data on the Refresh button click but not on loading I suppose there is something preventing it from that. Maybe a script or AutoBind property set to false?

    Additionally, I could suggest serializing the JSON in CamelCase by locating the ConfigureServices method in the project and adding the below

    public void ConfigureServices(IServiceCollection services)
    {
        ...
        // Maintain the property names during serialization.
        // For more information, refer to https://github.com/aspnet/Announcements/issues/194.
        services
            .AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1)
            .AddJsonOptions(options =>
                options.SerializerSettings.ContractResolver = new DefaultContractResolver());
    
        services.AddKendo();
    }

    More information can be obtained in the following documentation page:

    Let me know if this helps.

    Regards,
    Nikolay
    Progress Telerik

    Progress is here for your business, like always. Read more about the measures we are taking to ensure business continuity and help fight the COVID-19 pandemic.
    Our thoughts here at Progress are with those affected by the outbreak.
  4. Naga
    Naga avatar
    3 posts
    Member since:
    Jul 2020

    Posted 08 Jul 2020 in reply to Nikolay Link to this post

    Hi Nikolay,

     

    Thank you for your reply.

    I have already added these settings to the startup and also set AutoBind(true) explicitly. Grid always shows data on pager refresh icon but not on load. I am using .Net Core 2.2 framework.

    Thanks,

    Sameer

  5. Nikolay
    Admin
    Nikolay  avatar
    302 posts

    Posted 13 Jul 2020 Link to this post

    Hi Naga,

    Thank you for getting back to me.

    This behavior is quite unusual and based on the provided it is hard to tell what might be the cause of it.

    For your convenience, I am attaching a small MVC Core project implementing a Kendo UI Grid Ajax bound to the controller. The data is correctly loaded initially. Please examine it and let me know if this gives any hints on the situation.

    Alternatively, I could best advise you to submit a support thread attaching a sample runnable page that clearly replicates and isolates the problem. Examining this page locally will help us fully understand the case and investigate further.

    Regards,
    Nikolay
    Progress Telerik

Back to Top