This is a migrated thread and some comments may be shown as answers.

Refreshing grid after insertinbg a row

6 Answers 40 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Simon
Top achievements
Rank 1
Simon asked on 24 Jun 2015, 04:02 PM

I'm inserting a row into my grid, with a default ID of zero, and when I save it I'm setting the ID on the server.

I now want to refresh the grid so it includes the new ID value, rather than the default, so that I can re-edit the row (if it stays with a zero ID it tries adding it as a new row again).

I can achieve this by adding grid.dataSource.read(); to the requestEnd event, but this refreshes the whole grid, moving the new row to its correct position depending on sort order (which might be on a different page). I want the display to remain the same, with the new row at the top.

I've found a lot of similar posts, and the solution usually offered is that if the new row is returned from the Post method is the same format as the Get method returns, then everything should refresh automagically.

I can't get this working though. Perhaps the two methods don't return compatible results?

My Get method returns IHttpActionResult

    return Ok<PageResult<CurrencyViewModel>>(result)

but my Post method returns Task<IHttpActionResult>

    return Ok(currency)

 

Any ideas? I can post more source code if needed but don't want to confuse matters by posting lots of irrelevant stuff!

Thanks

6 Answers, 1 is accepted

Sort by
0
Alexander Valchev
Telerik team
answered on 26 Jun 2015, 11:03 AM
Hi Simon,

Your understanding is correct - the new row, returned from the server in response to the create request, should be in the same format as the data returned in response to the read request.

In case you have troubles with the server side implementation I suggest you to check one of our sample projects and examine the read/create server implementation.
  • https://github.com/telerik/kendo-examples-asp-net-mvc
  • https://github.com/telerik/kendo-examples-asp-net

Regards,
Alexander Valchev
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
0
Simon
Top achievements
Rank 1
answered on 29 Jun 2015, 09:26 AM

Thanks for that. I've changed my Get and Post methods so that both return the same data type IHttpActionResult but it's still not working.

Does it matter that Get returns Ok(PageResult) and Post returns OK(MyViewModel)? Will I need to rewrite so both return exactly the same? I don't want to go through the pain of doing that if it's not going to work!

0
Alexander Valchev
Telerik team
answered on 01 Jul 2015, 07:40 AM
Hi Simon,

Could you please provide a sample of the JSON response that is returned from the server in both cases so I can examine it?

Regards,
Alexander Valchev
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
0
Simon
Top achievements
Rank 1
answered on 06 Jul 2015, 09:53 AM

Get:

{"items":[{"guid":"f47a427c-827b-469a-ad32-f0ebc3462f3a","name":"£","description":"Sterling","symbol":"£","isHomeCurrency":true,"decimalPlaces":2,"alternativeCurrencyCode":"quid","currencyRates":[]}],"nextPageLink":null,"count":1}

 

Post:

{"guid":"0c8da5c3-fa91-4189-862a-f6daf287629e","name":"xc","description":"xc","symbol":"xc","isHomeCurrency":false,"decimalPlaces":2,"alternativeCurrencyCode":"xc","currencyRates":[{"guid":"7c67ebea-0cc0-4917-8585-8ce8d8f9edd3","exchangeRateHome":1.0,"dateEffectiveFrom":"2015-07-06T00:00:00+01:00"}]}

0
Accepted
Alexander Valchev
Telerik team
answered on 08 Jul 2015, 07:43 AM
Hello Simon,

Please modify the post service to return a response in the following format:

{
    "items": [{
        "guid": "0c8da5c3-fa91-4189-862a-f6daf287629e",
        "name": "xc",
        "description": "xc",
        "symbol": "xc",
        "isHomeCurrency": false,
        "decimalPlaces": 2,
        "alternativeCurrencyCode": "xc",
        "currencyRates": [{
            "guid": "7c67ebea-0cc0-4917-8585-8ce8d8f9edd3",
            "exchangeRateHome": 1.0,
            "dateEffectiveFrom": "2015-07-06T00:00:00+01:00"
        }]
    }]
}


Regards,
Alexander Valchev
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
0
Simon
Top achievements
Rank 1
answered on 10 Jul 2015, 10:24 AM
Thanks, that's solved it :-)
Tags
Grid
Asked by
Simon
Top achievements
Rank 1
Answers by
Alexander Valchev
Telerik team
Simon
Top achievements
Rank 1
Share this question
or