Define a part of fields for remote datasource

2 posts, 0 answers
  1. Lei
    Lei avatar
    4 posts
    Member since:
    Nov 2012

    Posted 21 Dec 2012 Link to this post

    I have a datasource binding to remote data. The model of remote data has many fields. I found that if I do not define schema.model.fields, all fields from remote will be processed, while if I define it, only data in defined fields will be processed. I just want to define part of remote fields, let other fields be defaults.

    ds = new kendo.data.DataSource({
        schema: {
            model: {
                id: 'UID',
                fields: {
                    UID: { type: 'number', defaultValue: -1 }
                    // Can I ignore other 20+ fields?
                }
            },
        },
        transport: {
            read: '/Path/To/ReadData',
    create: ...,
    update: ...
        }
    }

    The reason I want to do so is, when I add an item to the datasource then sync, the create action is not triggered. I debugged into source code and found that for the new item, its status is not 'created' since my default value -1 is not equal to "default" defaultValue of ""(empty string). So I think if I could define the id field and ignore other fields, this could be resolved. I know I can define all fields to make it work, but those other fields I don't care. For now, as a workaround, I have to set the id of new item to empty string to make create new item working.

    Thanks,

    Lei
  2. Alexander Valchev
    Admin
    Alexander Valchev avatar
    2894 posts

    Posted 25 Dec 2012 Link to this post

    Hi Lei,

    It is not mandatory to define all the fields of the DataSource - only the ID field is required.
    Please have in mind that if you do not define the type of other fields they will be considered and processed (sorted, filtered, etc.) as strings.

    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!
Back to Top