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

Overriding datasource's JSON parse and stringify - wholesale

10 Answers 952 Views
Data Source
This is a migrated thread and some comments may be shown as answers.
Michael
Top achievements
Rank 1
Michael asked on 01 May 2012, 06:54 PM
Is there any way to override the way the datasource is parsing and stringifying the JSON data, when using the transport? Currently, the Kendo utilities do not handle dates right (at least when using ubiquitous .NET/JSON server libraries). So on both the parameterMap and parse config lines, I have overrides there but they are hardcoded to specific fields since having to deal with javascript object/property level still.

What I want to do is take over the whole parse and stringify with a client library that handles dates better. I cannot seem to hook in the right place - before the raw data is already treated by the Kendo utils. Is this possible while using the rest of the transport functionality and if so, where do I intercept this?

Thanks!
Mike

10 Answers, 1 is accepted

Sort by
0
Michael
Top achievements
Rank 1
answered on 02 May 2012, 03:55 PM
Anybody....anybody??
0
Rosen
Telerik team
answered on 03 May 2012, 08:07 AM
Hello Michael,

You may use scheme parse function in order to do some preprocessing  to the raw data before it is used by the data source. However, note that with Q1 2012 version of KendoUI, DataSource component will handle conversion of .NET date literals automatically, if model fields with correct type are declared, as shown in this online demo.

Regards,
Rosen
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Michael
Top achievements
Rank 1
answered on 03 May 2012, 05:21 PM
As I mentioned in the OP, I am already using schema's parse config option. However, it is acting on anything but raw data. Raw to me would mean the JSON data, which is what I am looking for to be able to take over the JSON deserialization to a javascript object. As a result, I have to hardcode each date field to cast, and that is not generic.

That said, you are correct that the newer release handles the .NET serialization. I am not sure how I did not discover that but maybe I was not trying the right combo of settings. Anyway, the reads work good now. Thanks for that!

However that is only half of my issue. On the outgoing side (update/create posts), I am currently having to handle the parameterMap hook and likewise, serialize the dates into a transportable format that works in .NET JSON deserialization. And same issue, I have to property-for-property, add a harcoded line for each date field to serialize to JSON using a different client library. Thus it is not generic for all datasets and I want to avoid. 

I tried just now with the latest library and settings you demonstrated, and it still fails. It fails in that it appears (by inspecting the request sent), that nothing is being JSON serialized despite having declared a JSON type for the update in the transport config. Thus on the .NET side, this URL-encoded date literal is being set to NULL since unable to rehydrate from that format.

So I guess my question is just why isn't the outgoing request serializing this data into JSON and how to change that. Any insight or help here?? 

Thanks!
Mike
0
Michael
Top achievements
Rank 1
answered on 03 May 2012, 06:34 PM
An update to my previous post. I was able to get this resolved. I guess it seems we are responsible for packaging the outgoing data and that the contentType and type options are just part of the underlying ajax call and simply passed thru, and Kendo doesn't interpret those and modify the data payload accordingly.

So with parameterMap, I just took the data passed in, and stringified the whole object and returned that result. That works and was the final missing link. I am just a little dismayed that I didn't see this mentioned or exemplified anywhere! I was under the impression that parameterMap existed for doing additional transformations as needed (as the examples demonstrated). However, returning json data to the server, it is required that you perform this conversion, otherwise it just sends generic querystring/post parameters. 

It would be nice if any of this was documented and would have saved a lot of time. Or just a one single example demonstrating a transport config, with either update or create, using both POST and JSON submission together. For such an absolute common pattern, I am amazed there isn't one example of this between the grid and datasource docs.examples. 

Please confirm my assumptions in the event I am overlooking something else. Otherwise, this can be closed now.

Thanks,
Mike
0
Rosen
Telerik team
answered on 04 May 2012, 06:51 AM
Hello Michael,

Indeed, you should use the parameterMap to modify the send parameters in the appropriate format for the server technology you are using. You can find various examples of using paramterMap for this purpose here.  Also note that almost all of the online grid editing demos are using the parameterMap to convert the changed records.

Regards,
Rosen
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Michael
Top achievements
Rank 1
answered on 04 May 2012, 07:19 AM
Fair enough, I overlooked that example. Hopefully however we can all agree there is no actual documentation or mention anywhere, outside the forums and a couple obscure examples that have settings but with zero explanation as to whether it even pertains to the example.

In fact, most of Kendo examples have no narrative at all with many attributes set, not always relevant to the example. That is a very inefficient way to instruct, especially when in many of these cases, there are so many details that determine when to use this or that configuration and many settings are mutually exclusive. Leads to confusion and misuse. 

So I guess what I am hoping is that the Kendo team can take only a little amount of time to properly document these key function and configs. And referring folks to the forum for proper docs is a very lazy approach. No disrespect, it just doesn't respect my time. That said, unfortunately, that is what I have had to do to get any real understanding, reading every single thread, looking for hidden gems of insight often not even directly related to the thread.

Thanks,
Mike
0
Rosen
Telerik team
answered on 04 May 2012, 11:26 AM
Hi Michael,

We do realize the importance of good documentation and examples, that is why the improvement of docs have a very high priority for us in next Q2 release.
You could read more about upcoming changes, documentation plans and new features in this blog post.

All the best,
Rosen
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Michael
Top achievements
Rank 1
answered on 04 May 2012, 04:03 PM
Very good, then I will stop bashing the point. :) I suppose some of this is due to how excited at first I was with how quickly I was up and going on the Kendo suite, but then time saved up front tho later spent at the end is to no gain and actually rather frustrating. Nuf said, you guys get it.

To end on a better note, I do really love what you guys are doing with Kendo. I am building a product with some tough competition already in play (including one built in Flash). I had purchased $3K in components at the beginning of the year, mostly from Telerik and C1, but have loved the Kendo suite and have actually managed to keep the 3rd-party use to only Kendo's offering (and jQuery plugins of course). I have had to build some key controls that are missing from Kendo's suite but I used some existing Kendo controls as the basis for most. 

So despite my criticism, I do believe in this suite and am thankful for it! I just wish I could have saved myself $2,200!!!

Cheers,
Mike
0
autoabacus
Top achievements
Rank 1
answered on 09 Jul 2012, 06:58 AM
I downloaded the Q2 Beta in the hope of finding some of the improved documentation mentioned here, but do not see any.

When might we see the better documentation please?

The current documentation is frustratingly poor, and a great obstacle to using Kendo UI in other than the most trivial ways. It is hugely time wasting to have to use a debugger to attempt to work out what is happening e.g. what the arguments passed to parameterMap() are which the doc doesn't define and so on. Or to download the full source and study the source code.

Also, I am using php in LAMP/WAMP envionments, as are many other developments, yet all non-totally trivial examples of the use of Kendo appear to be for asp net. Why? (I did notice an aspnetmvc subdirectory in the Q2 beta examples tree but not one for php or other server side language.)
0
autoabacus
Top achievements
Rank 1
answered on 12 Jul 2012, 06:36 AM
The Q2 doc released 11 Jul 12 is indeed much better. However, it is still far from being complete or as helpful as I would like to see.

In attempting to use Kendo grid for my application as a trial of Kendo I keep coming across DataSource transport issues that the doc does not address. Support is so horribly slow (72 hours for a trial user) that I will now resort to studying the full source code to try to work things out for myself. I like much of what I see about Kendo but am very disappointed in the doc, and the need for me to go to source code to try to use the system.

I do note re my previous post that the Q2 doc does include a php example. Good. (Though it does not help with my particular issues.)
Tags
Data Source
Asked by
Michael
Top achievements
Rank 1
Answers by
Michael
Top achievements
Rank 1
Rosen
Telerik team
autoabacus
Top achievements
Rank 1
Share this question
or