Data not refreshing in Grid View

This is driving me a bit nuts. I've been going for hours and can't work out where I've gone wrong.


I have a Grid that is being populated fine - but when I use the following script to refresh the data based on a datepicker, it throws a 500 error.

<script>

    function submit(args) {

        var dateStr = args.value.toUTCString(); // Convert to UTC string

        $.ajax({

            type: "GET",

            url: '@Url.Action("ResourceListDatasource", "Resourcing")',

            data: { date: dateStr },

            success: function (data) {

                var grid = document.getElementById("Grid").ej2_instances[0];

                grid.dataSource(data);

                grid.refresh();

            }

        })

    }

</script>

The Controller is showing all the right records (based on the selected date) but it won't refresh. 

Any ideas?

Controller Code (which works fine for the initial load of the Grid):

  public ActionResult ResourceListDatasource(DataManagerRequest dm)

        {

            IEnumerable<BookingsClassModel> DataSource = null;

            string dateAsString;

            string selectedDate = null;

                selectedDate = Request.QueryString["date"].ToString();

            if (selectedDate == null)

            {

                DateTime currentDate = DateTime.Now;

                dateAsString = currentDate.ToString("yyyy-MM-dd");

            }

            else

            {

                DateTime date2 = DateTime.Parse(selectedDate.ToString());

                dateAsString = date2.ToString("yyyy-MM-dd");

            }

            DataSource = BusinessLogic.Processors.BookingsProcessor.GetBookingsResourcing(dateAsString);

            int count = DataSource.Cast<BookingsClassModel>().Count();

            return dm.RequiresCounts ? Json(new { result = DataSource, count = count }) : Json(DataSource);

        }

    }



1 Reply

HS Hemanthkumar S Syncfusion Team August 30, 2023 11:21 AM UTC

Hi Georg Thomas,


Greetings from Syncfusion support.


Query: Data not refreshing in Grid View. When I use the following script to refresh the data based on a datepicker, it throws a 500 error.


Based on the code you provided, it's evident that you're attempting to assign data to the dataSource property of the Grid and have used the dataSource property as a method. This approach can potentially lead to a 500 error. As a suggestion, we recommend avoiding the use of the dataSource property of the Grid as a method. Instead, utilize it solely as a property to assign data to the Grid.


For more information, please refer to the below code example and documentation.


success: function (data) {

var grid = document.getElementById("Grid").ej2_instances[0];

grid.dataSource = data;

grid.refresh();

}


dataSource API: https://ej2.syncfusion.com/documentation/api/grid/#datasource


If the above information is not helpful, then we need some information to better understand the issue you are facing. Please provide us with the following details:


  1. Provide a detailed description of the issue you are currently facing and what your expected scenario is.
  2. Are you working with local data or remote data? In the case of remote data, provide information about the type of adaptor you are utilizing.
  3. Could you please provide a detailed description of the purpose or reason behind your attempt to refresh the data based on a date picker?
  4. Are you encountering any script errors while refreshing the data based on a date picker? If so, provide an image or description of the script error, as it will assist us in identifying the cause of the issue.
  5. Share the complete code for rendering the Grid. Having the full code will allow us to review the implementation and potentially identify any issues or suggest improvements.
  6. Provide the version of the Syncfusion package that you are using.
  7. Sharing a video or screenshot demonstration would greatly assist us in better understanding your query. It would allow us to visualize the problem and provide more precise guidance or suggestions.
  8. Share the reproducible sample that showcases the issue. Having a sample will enable us to directly analyze and validate the problem, which can lead to a faster resolution.


We appreciate your cooperation in providing us with the requested information, as it will help us provide a more effective solution to your query.


Regards,

Hemanth Kumar S


Loader.
Up arrow icon