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

Unexpected number error when using a function for DataSource transport update

3 Answers 951 Views
Data Source
This is a migrated thread and some comments may be shown as answers.
Gareth
Top achievements
Rank 1
Gareth asked on 16 Apr 2013, 03:33 AM
I am using:
 - Kendo UI Complete 2013.1.319
 - Windows 7 64-bit
 - Google Chrome 26.0.1410.64 m
 - The jQuery bundled with Kendo

I have the following HTML:
<div id="app"></div>
 
<script type="text/x-kendo-template" id="users">
  <div data-role="grid" data-filterable="true" data-editable="true" data-sortable="true" data-bind="source: usersSource" data-columns="[{ field:'username', title:'Username' }, { field:'fullname', title:'Full Name' }, { command:'destroy' }]"></div>
</script>
And the following JavaScript:
var usersModel = kendo.observable({
    // the users data
    usersSource:new kendo.data.DataSource({
        autoSync:true,
        schema:{ model:{ id:"_id" } },
        transport:{
            create:{ url:"/user", dataType:"json", type:"POST" },
            destroy:{
                url:function (user) {
                    console.log(user)
                    return "/user/" + user._id + "/" + user._rev
                },
                type:"DELETE",
                dataType:"json"
            },
            read:{ url:"/users", dataType:"json" },
            update:{ url:"/user", dataType:"json", type:"POST" }
        }
    })
});
 
var usersView = new kendo.View("users", { model:usersModel});
var router = new kendo.Router({
    init:function () {
        usersView.render("#app");
    }
});
 
$(function () {
    router.start();
});
This all works as expected - I can update the data in the grid. I am however storing the data in couchdb and need to update the data source with the new revision number after create and update events are complete.

I think that I need to replace the object I'm using with create and update with a function to allow me to do this. I have attempted to do this with just a simple function as shown below:
/* trimmed */
update:function(options){console.log(options);}
/* trimmed */
This however results in an error on the JavaScript console when I modify a record in the grid:
Uncaught SyntaxError: Unexpected number     kendo.web.min.js:9
st.setter                                   kendo.web.min.js:9
tt.extend._set                              kendo.web.min.js:11
zt.extend.accept                            kendo.web.min.js:11
tt.extend._accept                           kendo.web.min.js:11
(anonymous function)                        kendo.web.min.js:11
(anonymous function)                        jquery.min.js:3
c                                           jquery.min.js:3
p.fireWith                                  jquery.min.js:3
i.(anonymous function)                      jquery.min.js:3
a.(anonymous function).call.q.success       kendo.web.min.js:11
c                                           jquery.min.js:3
p.fireWith                                  jquery.min.js:3
k                                           jquery.min.js:5
r                                           jquery.min.js:5
Where is the mistake I'm making? I also tried copy-and-pasting the exact declaration from the documentation for transport.update with the same results.

3 Answers, 1 is accepted

Sort by
0
Alexander Valchev
Telerik team
answered on 17 Apr 2013, 03:32 PM
Hi Gareth,

Such error occurs when the transport definitions are inconsistent. In other words, if you would like to use custom transport method, all transport types should be defined as functions.

Having a standard read transport and custom update is not supported. Please configure all transports as functions and let me know if the error still occurs.

Kind regards,
Alexander Valchev
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Stuart
Top achievements
Rank 1
answered on 17 Apr 2015, 12:41 AM
It would definitely be worth including that information in the documentation, it would have saved me a lot of time.
0
Alexander Valchev
Telerik team
answered on 20 Apr 2015, 04:06 PM
Hello Stuart,

Thank you for the feedback. At which place do you think it would be best to include this information?

If you wish you may event include it and make a pull request, the documentation is public and open source.


Regards,
Alexander Valchev
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
Tags
Data Source
Asked by
Gareth
Top achievements
Rank 1
Answers by
Alexander Valchev
Telerik team
Stuart
Top achievements
Rank 1
Share this question
or