1

I have a form to add admin user to a site. Multiple users can be added at once. OnSuccess, I need to append the users to a Kendo Grid (Table). How can I append all three users when the AJAX response looks like this.

{ "Result": true, "Message": "Success!", "AccountRoleId": 106, "Users": [ { "FirstName": "Joe", "LastName": "Smith", "Email": "[email protected]", "Status": 1 }, { "FirstName": "John", "LastName": "Doe", "Email": "[email protected]", "Status": 1 }, { "FirstName": "Al", "LastName": "Jones", "Email": "[email protected]", "Status": 1 } ] } 

This script will not work I keep getting a single entry of undefined undefined, added to the Kendo table after the form is submitted.

var newRow = { FirstName: response.Users.FirstName, LastName: response.Users.LastName, Email: response.Users.Email, Status: response.Users.Status }; var grid = $("#UsersTable-").data("kendoGrid"); grid.dataSource.add(newRow); 

    1 Answer 1

    0

    You have to access the property Users which has an array. This will render the grid.

    var grid = $("#UsersTable-").data("kendoGrid"); if(response.Result) { response.Users.forEach((item) => { item.Status = item.Status || 0; }); grid.dataSource.add(response.Users); } else { console.error('unable to fetch data'); } 
    5
    • Thanks Naren Murali, this is so close. unfortunately, I'm getting "Status" is undefined
      – esoteric
      CommentedAug 13, 2024 at 14:57
    • @esoteric There is no status line in the question, please share the line where the error occours, if possible a working exampleCommentedAug 13, 2024 at 16:34
    • Naren Maruli the "Status" is in the response for the user records, there is a value for each but for some reason Kendo is telling me it is undefined. { "Result": true, "Message": "Success!", "AccountRoleId": 106, "Users": [ { "FirstName": "Joe", "LastName": "Smith", "Email": "[email protected]", "Status": 1 },
      – esoteric
      CommentedAug 13, 2024 at 16:39
    • @esoteric updated answer, with a default value for Status if not presentCommentedAug 13, 2024 at 16:48
    • Thanks Naren Maruli, still have the issue, there is always a status value, the existing code was a single select box and it was updated to a multiselect. Everything is good on the backend . If I refresh the page the table is correct. It seems I am not adding the response users correctly.
      – esoteric
      CommentedAug 13, 2024 at 17:22

    Start asking to get answers

    Find the answer to your question by asking.

    Ask question

    Explore related questions

    See similar questions with these tags.