Issue encountered in Kendo grid: kendo.all.min.js file throwing a TypeError stating that e.slice is not a function

I am currently working with a kendo grid that binds its data source using ajax in JavaScript. Here is how it's set up:

Kendogrid:

@(Html.Kendo().Grid<WEB02.ConfigurationModel.ActivityGridDetails>()
.Name("Activitydet")
.Columns(columns =>
{
    columns.Bound(o => o.Id).Width(40);
    columns.Bound(o => o.Config).Width(200);
    columns.Bound(o => o.Status).Width(250);
    columns.Bound(o => o.In).Width(250);
    columns.Bound(o => o.Out).Width(250);

})
.DataSource(dataSource => dataSource
    .Ajax()
    .Events(events => events.Error("error_handler"))
     .Model(model => model.Id(p => p.Id))
    )
)
)

JavaScript:

function onChange(e) {
    var grid = $("#grid").data("kendoGrid");
    var dataRows = grid.items();
    var rowIndex = dataRows.index(grid.select());
    var selectedname = grid.dataItems()[rowIndex];
    console.log("aly" + selectedname.NodeId);
    document.getElementById("ActivityGrid").style.bottom = "100px";

    $.ajax({

        type: 'POST',
        url: '/Configuration/ActivityGridDisplay/',
        dataType: 'json',
        data: { nodeName: selectedname.Name, nodeType: selectedname.Type, nodeID: selectedname.NodeId },
        success: function (result) {

            $("#Activitydet").data("kendoGrid").dataSource.data(result);
        }
    })}

Controller:

public ActionResult ActivityGridDisplay([DataSourceRequest] DataSourceRequest request, string nodeName, string nodeType, string nodeID)

    {

        // Controller logic here...

        return Json(Table.ToDataSourceResult(request));

}

I have successfully implemented a similar grid using the model directly without any issues. However, when I tried to bind the data using ajax this time, it resulted in an error message: "Uncaught TypeError: e.slice is not a function". I've attempted different solutions such as adjusting the JSON call and setting a model ID, but with no success. Removing the DataSource part from the Kendo Grid also did not resolve the issue. Any suggestions on how to fix this problem?

Answer №1

Identified the issue: The problem lies within the javascript section where the entire data is being passed instead of just the data array section:

The ajax function needs to be modified as shown below:

 $.ajax({

        type: 'POST',
        url: '/Configuration/ActivityGridDisplay/',
        dataType: 'json',
        data: { nodeName: selectedname.Name, nodeType: selectedname.Type, nodeID: selectedname.NodeId },
        success: function (result) {
            console.log(result);
            var pass = result.Data;
            $("#Activitydet").data("kendoGrid").dataSource.data(pass);
            //$("#Activitydet").data("kendoGrid").dataSource.fetch();
        }
    })

Answer №2

Encountered a similar problem with $("#grid").kendoGrid but found a solution by including the 'data' attribute in the controller logic. For instance: return Json(response.Data, JsonRequestBehavior.AllowGet);

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Sending encoded Base64 data through an HTTP REST service and receiving a JSON response

I have a webservice that returns a JSON response containing both plain text and base64 encoded images. I am using this service in an Android app, where I implemented a progress bar to show the progress of the data being retrieved. To implement the progres ...

What is the reason for the excessive number of #undefs in this Dict? Is there a way to filter them

When working with Julia, I am faced with the challenge of reading and interpreting JSON data. Despite my efforts, I keep encountering numerous instances of #undef. How can I create an array that does not include these undefined values? using JSON source ...

Utilizing executions.ftl in Spring Batch to enhance my custom controller

I've recently incorporated a new feature in my Spring Batch project to filter job executions. To achieve this, I created a new Controller: @Slf4j @Controller public class FilteredJobExecutionResource { @Autowired @Qualifier("filteredJobExecu ...

I can't figure out why my code is only returning the else statement and an undefined value instead of the totalBasketballScore

I was confident that my code was correct, but I am encountering an issue when trying to calculate basketball scores based on free throws, 2 pointers, and 3 pointers. Whenever I console.log the totalBasketballScore, the output is 'All entries must be n ...

How can I retrieve the postback element from an updatepanel using JavaScript?

Is it possible to identify the postback element within an updatepanel using JavaScript? I attempted the code below, but args.get_postBackElement().id returns as undefined. <script> Sys.WebForms.PageRequestManager.getInstance().add_beginReques ...

Creating a network of lists by combining multiple arrays

I'm currently working on generating a comprehensive list of all possible combinations of multiple arrays. While I have experience in Matlab and understand loops and basic coding principles, I'm unsure of the most efficient method to compile these ...

Unfortunately, the server experienced a temporary error and was unable to fulfill your request at this time

When testing the Google Speech API for the first time, I followed the example provided in Google's demo and it was successful. { "config": { "encoding":"FLAC", "sample_rate": 16000, "language_code": "en-US" }, "audio": { ...

How can you attach an event handler to an HTML button without disrupting its default behavior?

I am working on enhancing a contact form to include a feature where the submit button becomes disabled for five seconds after it is clicked. This is to prevent accidental repeat submissions from occurring. However, I am facing an issue where disabling the ...

Submit a JSON object containing just a single text string

Is there a way to post a JSON with just one line of text, for example: "Hello, I'm waiting for you" I attempted the following: { "":"Hello, I'm waiting for you" } Unfortunately, it did not work. Trying to post only the text also did not yield ...

Switch over to using a for loop

I have a query regarding implementing multiple toggles within a for loop. For instance, I want a toggle menu to appear when clicking on a div. Here is the code snippet: for (var i = 0; i < myObjectString.length; i++) { var obj = JSON.parse(myObjectStr ...

What is the best way to organize a complicated array of arrays in JavaScript?

Within my code, there exists an array known as generationArray. Each array contained within generationArray consists of 252 elements. The first 250 elements serve as internal coding data, while the final two positions are designated for sorting criteria. T ...

Allowing the contenteditable attribute to function only on a single line of

My app allows users to create different lists, with the ability to edit the name. However, I am facing an issue where if a user types a new name, it should remain on only one line. I tried adding max height and overflow hidden properties, but it only hides ...

I am working with a JSON Object in JavaScript and need to retrieve a key using a String variable

Working with a JSON Object in JavaScript can be tricky, especially when trying to access keys stored as Strings using the dot operator. Consider this example of JSON code: "values" : [ { "prop0" : "h", "prop1" : "pizza", "prop2" : "2014- ...

Ways to block past dates on bootstrap date picker starting from the current date and how to prevent dates beyond 90 days in the future from being selected on the

I am currently facing an issue with disabling previous dates from the current date in my code. While the functionality works well for the "From Date" date picker, I am having trouble implementing the same restriction for the "To Date" date picker after 90 ...

Refreshing div content on selection change using PHP ajax with Jquery

Here is my code for the portfolio.php file <select name="portfolio" id="portfolio_dropdown" class="service-dropdown"> <?php foreach($years as $year){ ?> <option value="<?php echo $year[&apo ...

Guide on implementing ES6 script's template literals

I've been tackling a template literal question on hackerrank. It's working smoothly on my local IDE, but encountering an error on the Hackerrank IDE. Here's the code to add two numbers and print the result using a template literal: const sum ...

Is there an alternative method to load a webpage with a large amount of POST data if the form POST function is not functioning properly with a massive JSON string?

I'm in the process of implementing a form to load a page with Post data. The post data consists of a large string, and I am uncertain if its length is causing any issues. The scenario involves a search page redirecting to a results page, which takes ...

What is the best way to display JSON data in a readable format?

I received a JSON file with the following structure: { "data":{ "uuid":"123", "name":"TestData", "alias":null, "created_at":"2021-03-17T11:57:29.000000Z&q ...

Using AngularJS routing with an Express 4.0 backend API

Recently, I began working on an application utilizing Express 4.0 server. Following a tutorial on scotch.io (http://scotch.io/tutorials/javascript/build-a-restful-api-using-node-and-express-4), I structured the routes to support a backend api serving an An ...

Initial Express.js GET request fails to retrieve data on first attempt

Currently, I am in the process of developing an application using Node/Express/MongoDB for the first time. The goal is to retrieve data from the database and present it on an Express page. Here is how the GET request is structured: var str = ""; ...