Extending ViewModel

6 posts, 0 answers
  1. KV
    KV avatar
    1 posts
    Member since:
    Mar 2012

    Posted 21 Jun 2013 Link to this post

    Is there a way to extend the viewmodel similar to how we extend the class using partial?
    For example, a ViewModel will be pre-defined by product team.
    Customers can then extend the viewmodel if required to add additional validations in a custom js file or part of html.
  2. Daniel
    Admin
    Daniel avatar
    2226 posts

    Posted 25 Jun 2013 Link to this post

    Hello,

    I posted my reply in the support ticket on the same ticket. For convenience, I am pasting the relevant part below:
     
    To extend a Kendo Model you can use the extend method:

    var baseModel = kendo.data.Model.define({
        fields: {
            ID: {editable: false},
            MyNumber: {type: "number"}
        }
    });
      
    var childModel = baseModel.extend({
        fields: {
            MyNumber: { validation : { min: 1, max : 1000}}
        }
    });
      
    var model = childModel();
    Regards,
    Daniel
    Telerik
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
  3. Paolo
    Paolo avatar
    30 posts
    Member since:
    Mar 2017

    Posted 24 Apr in reply to Daniel Link to this post

    Hi Daniel

    I have an old project where we have 2 models we discovered own common fields, after reading your post we selected common fields and methods and pushed up in a commond base model, but application stopped to work, we prepared a sample code

     

    https://dojo.telerik.com/ejAxuPiV/2

     

    The problem is we rely on some fields are nullable == true, after applying suggested changed those fields are equal undefined and they should be null instead, so I think there are a lot of malfunction

     

    In our application we set up datasource via DataSource.create([ ...]) with a list of models that miss fields have a default value nullable, and we want they stay null if are not defined 

     

     

  4. Veselin Tsvetanov
    Admin
    Veselin Tsvetanov avatar
    973 posts

    Posted 26 Apr Link to this post

    Hi Paolo,

    I have reviewed and researched the issue observed. Nevertheless, I did not manage to isolate the root cause that causes the discussed. We will give another try to that scenario. I will come back to you as soon as I know something more on that matter.

    Regards,
    Veselin Tsvetanov
    Progress Telerik
    Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
  5. Paolo
    Paolo avatar
    30 posts
    Member since:
    Mar 2017

    Posted 02 May in reply to Veselin Tsvetanov Link to this post

    Hi Veselin, We want to share with Telerik a patch for our specific case and now we can make it works as we wanted :

     

    Model.define = function (base, options) {
            if (options === undefined) {
                options = base;
                base = Model;
            }
            var model, proto = extend(true,{ defaults: base.defaults || {}, fields: base.fields || {} }, options), name, field, type, value, idx, length, fields = {}, originalName, id = proto.id, functionFields = [];
     
            // ....
            // ....
    }

     

    In details we added special dealing of fields and defaults property on the base model, they need to be copied onto child model, I hope this could be a worthwhile patch

     

  6. Veselin Tsvetanov
    Admin
    Veselin Tsvetanov avatar
    973 posts

    Posted 06 May Link to this post

    Hi Paolo,

    Thank you for the detailed review of the case and for the suggested solution that would facilitate the scenario in question. Based on that I have created the following item in our backlog. As soon as our priority queue allows it, we will carefully examine the proposal to decide on how to integrate it in the Model.define() implementation.

    As a small token of gratitude for helping us improve our code base I have updated your Telerik points.

    Regards,
    Veselin Tsvetanov
    Progress Telerik
    Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Back to Top