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

Why should be used a Schema Model Field Type defined as "object" ( nested or complex type ?? )

18 Answers 1444 Views
Data Source
This is a migrated thread and some comments may be shown as answers.
Paolo
Top achievements
Rank 1
Paolo asked on 17 May 2017, 10:37 AM

I cannot understand the following sentence from https://goo.gl/q14C6L very well

The dataSource is designed to work with flat (not nested) data. Defining a 'complex' objects in the schema.model is not supported

For this reason I think there is on schema model the from property which allow to rename / alias data fields ( for example from a foreign remote server )

Yes , but if dataSource doesn't support complex object why :

  1. in the schema.model.<fieldN>.type is present a 'object' type ?
  2. in the grid for example is available dot notation to retrieve in some place a nested value on model ?? es: Category.name - is it not in contrast with previous sentence  ?

Also - What is the role of field.type == object during various operation ?? for example if I have a datasource with a field of type object in a grid, it is normally rendered like a string. How is it related to defaultValue ??

So I cannot understand why  documentation is not coherent

 

Thanks

 

18 Answers, 1 is accepted

Sort by
0
Boyan Dimitrov
Telerik team
answered on 19 May 2017, 07:37 AM

Hello,

This statement is actually true and the DataSource is not designed to work with complex objects internally. The reason why there is an type object in the schema.model is because JavaScript data types includes object. Indeed you are able to use dot notation and having nested field (since it is JavaScript after all), but the Kendo UI DataSource is designed (internally) to expect and work only with flat data. 

The default value should be set in the schema.model configuration as demonstrated in the Grid / Editing custom editor demo with the Category field. 

Regards,
Boyan Dimitrov
Telerik by Progress
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
0
Paolo
Top achievements
Rank 1
answered on 28 Sep 2017, 04:06 PM

Thanks for your answer, I also noticed that the default type is not string:

options.fields.fieldName.type String
Specifies the type of the field. The available options are "string", "number", "boolean", "date" and "object". The default is "string".

 

See following PHP code , we have dynamic model fields :

 

foreach ($activities as $key => $activity){
            $this
                ->addField((new DataSourceSchemaModelField('activity_'.$activity->id))
                    ->type('object')
                    ->editable(true)      
                    ->defaultValue([
                        'priority' => 0,
                        'member' => null,
                        'status' => null
                    ])
 
                );
        }

 

I have a complex type ( object ) for these model fields, as you can see in default value

var serverResponse = {
    data: [{
        activity_1: {
            member: 2, member_name: "AMatteo", status: null, status_color: null, priority: 0
        },
        activity_6: {
            member: 1, member_name: "Paolo", status: 3, status_color: "#ff7f27", priority: 0
        },
        activity_7: {
            member: 1, member_name: "Paolo", status: null, status_color: null, priority: 0
        },
        activity_9: {
            member: null, member_name: null, status: 3, status_color: "#ff7f27", priority: 0
        },
        description: "asdfadf",
        id: 1,
        note: "*",
        project_details_id: 1
    }],
    total: 1
};

 

also I have a custom template editor see attached image , my app is correctly working now , but I cannot match the app behaviour with the initial statement about type default :

  1. type == 'object' : all works as expected, data from server is left untouched and I can correctly serialize it thanks to multiple data-bind value in template editor ( the last in the post )

    activity_1[member]:2
    activity_1[member_name]:AMatteo
    activity_1[status]:
    activity_1[status_color]:
    activity_1[priority]:0
    activity_6[member]:1
    activity_6[member_name]:
    activity_6[status]:3
    activity_6[status_color]:#ff7f27
    activity_6[priority]:0
  2. remove any type attribute : same as point 1 , all is working , but the doc says the default is string ....
  3. let's explicit type == 'string' : now the code stop working, I did't debug but the behaviour between type == string and type not specified is different !! is the doc wrong ?

Thanks !

<script type="text/x-kendo-template" id="activity-preview-template">
        <div # if(color) { # data-color="#: color #" # } # style="position: relative;">
            #: text #
        </div>
        <div class="statusbox hide">
              
        </div>
        # if (priority!=0) { #
        <div class="priority"> </div>
        # } #
    </script>
    <script type="text/x-kendo-template" id="cell-template">
        <ul class="fieldlist">
            <li>
                <div>
                    <input tabindex="#: tabindex #" name="#: field #_member" data-bind='value: #: field #.member'
                           style="width: calc(100% - 28px); "></input>
                      <span class="k-icon k-i-user"> </span>
                </div>
            </li>
            <li>
                <div class="">
                    <input tabindex="#: tabindex + tabMax #" name="#: field #_status" data-bind='value: #: field #.status'></input>
                      <span class="k-icon k-i-clock"> </span>
                </div>
            </li>
            <li>
                <div class="">
                    <input tabindex="#: tabindex + tabMax * 2 #" name="#: field #_priority" min="0"
                           data-bind='value: #: field #.priority'></input>
                      <span class="k-icon k-i-warning .k-i-exception .k-i-error"> </span>
                </div>
            </li>
        </ul>
    </script>
0
Boyan Dimitrov
Telerik team
answered on 02 Oct 2017, 02:34 PM

Hello Paolo,

I am not sure that I fully understand the question here. Could you please send us a sample dojo that replicates the problem and provide some additional explanation? 

Regards,
Boyan Dimitrov
Progress Telerik
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
0
Paolo
Top achievements
Rank 1
answered on 04 Oct 2017, 09:26 AM

Hi, thanks, I can replicate but it needs a long time, my exact question is related to this sentence :

options.fields.fieldName.type String
Specifies the type of the field. The available options are "string", "number", "boolean", "date" and "object". The default is "string".

I supposed default type is "string" , so I wondered , which type would I have to choose for a complex data type (we have a grid cell custom editor template, see previous server response to understand, everty activity_N field i edited via cell custom editor in the image) ?

So i tried different values in schema model field type: string, object and 'no type non specified' , I supposed string and  'no type non specified' will behave in the same way, because the doc says the default is 'string', but it behaves differently

 

It seems my code works also with type not specified, instead if I put string it stop working. it is right that stop working with string, but it would stop working also when I dont explicitely specify type ...

 

Thanks

 

0
Boyan Dimitrov
Telerik team
answered on 06 Oct 2017, 09:41 AM

Hello Paolo,

I believe that Use Nested Model Properties can help you out to understand how nested model fields can be used with reading and editing operation. 

Regards,
Boyan Dimitrov
Progress Telerik
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
0
Paolo
Top achievements
Rank 1
answered on 09 Oct 2017, 01:02 PM

Thanks you Boyan, I didn't find that doc page before, I read carefully it !

My only question is the initial question :

When should be used a Schema Model Field Type defined as "object" ? 

I cannot find any examples about it and the doc says the default is string when it is left empty, and in your previous example we cannot find any presence of type == object

 

Thanks for your patience

0
Paolo
Top achievements
Rank 1
answered on 09 Oct 2017, 01:29 PM

Hi

I definitely look  into the code , and now I can understand :

  1. the doc says the wrong thing! the default is not string !!!! but 'default' , see the code, only default leaves the data untouched
  2. string correctly does a object cast, and in my case breaks the code !! so I cannot use string but I can left it empty because string is not the default !!!
  3. there is not presence of string 'object' in your code but only 'default' ! so it should be rectified 
var parsers = {
           'number': function (value) {
               return kendo.parseFloat(value);
           },
           'date': function (value) {
               return kendo.parseDate(value);
           },
           'boolean': function (value) {
               if (typeof value === STRING) {
                   return value.toLowerCase() === 'true';
               }
               return value != null ? !!value : value;
           },
           'string': function (value) {
               return value != null ? value + '' : value;
           },
           'default': function (value) {
               return value;
           }
       };

 

Model.define = function() {
    //....
   for (name in proto.fields) {
       field = proto.fields[name];
       type = field.type || 'default';
       // ..... My statement is confirmed ! type == 'object' has no meaning !!!
   }
}

 

 

0
Paolo
Top achievements
Rank 1
answered on 10 Oct 2017, 09:59 AM

Hi

I revised also the kendo editors generator in particular fieldType method :

fieldType = function(field) {
        field = field != null ? field : '';
        return field.type || $.type(field) || 'string';
    }

 

fieldType is used in many place to determine the field model type.

There we can see the default editor for model field with empty type property is 'string' so when a model field has no type the editor rendered is of string type. So I can further clarify :

  1. for models without a type property the default parser choosed is 'default' and not 'string' , no cast is done !!
  2. for models without a type property the default editor is 'string' 

I think this behaviour could be documented more deeply even if I think is conflicting ( default parser I think should adhere to default editor used ) 

at first I cannot truly understand it without code inspection

0
Alex Hajigeorgieva
Telerik team
answered on 11 Oct 2017, 09:05 AM
Hi, Paolo,

My name is Alex and I am taking over the thread from my colleague Boyan.

The Kendo UI Data Source Schema Model definition is important for the editing functionality of the Kendo UI Grid to work correctly. I believe the reason why we have reflected that the default type is a string is to inform our clients that if a type is not specified, the editor which will be generated is one for string type:

https://github.com/telerik/kendo-ui-core/blob/master/src/kendo.editable.js#L195

editor = editor ? editor : editors.string;

In addition to that, you can see that the default value for the "default" type is indeed empty string:

https://github.com/telerik/kendo-ui-core/blob/master/src/kendo.data.js#L657-L668

var defaultValues = {
  "string": "",
  "number": 0,
  "date": new Date(),
  "boolean": false,
  "default": ""
};

I also inspected the schema model fields serialization for MVC and the object types are serialized as "object":



I am wondering if what you are experiencing is anything specific to the PHP wrappers. If you can provide us with instructions how to reproduce the erroneous behaviour, we will be glad to investigate and amend the PHP data source model serialization as required.

Look forward to hearing back from you.

Kind Regards,
Alex Hajigeorgieva
Progress Telerik
Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
0
Paolo
Top achievements
Rank 1
answered on 11 Oct 2017, 03:23 PM

Hi Alex, thanks for joining the discussion, I will try to answer you more accurately

I needed in a situation to undestand which was the default parser and which the default editor, as you said I realized the model default is linked to the editor behaviour  , but in my app I have a custom editor that edits a property on model that is an object

{
   // grid columns edited by a custom editor match with an object model field activity_1
   activity_1: {
       member: 2, member_name: "AMatteo", status: null, status_color: null, priority: 0
   }
   // ....
}

 

so in my app I used on model type = 'object', as the doc says , to stop any string cast on server data ( even if in the code object does nothing !! )

I was only disappointed when I unintentionally removed the type properties on model, It didn't stop working !! I expected it should have stop working because the default is string and I thought the parsers should cast it to string

Reading the code I understood that in my case it is better leave the model type empty because it does the trick:

  1. this stop parsers to string cast on server data ( contrasting to the custom editor side which says string is default )
  2. I have not a default editor and I don't need to use type == 'string' , but leaving it empty I achieve my goal at the same time

In my scenario specifyng type == 'string' make app stop working because activity_1 is string casted and my custom editor cannot works anymore

0
Alex Hajigeorgieva
Telerik team
answered on 13 Oct 2017, 06:22 AM
Hi, Paolo,

I believe I understand your confusion and I will consult with the team for a better phrasing of this portion of our documentation. As a token of appreciation for helping us improve, I have also added some Telerik points to your account.

Now, I would like to shed some light why the Kendo UI Grid continues working.

The Kendo UI Grid continues working because in your case when there is a custom editor, the custom editor is used instead of the built-in ones. Since setting the type is optional, the type is checked internally, too.  The presence of the custom editor and the underlying object type evaluate this code to true:

isObject = isPlainObject(field), // this is the jQuery isPlainObject method
isCustomEditor = isObject && field.editor,  // the existing custom editor
editor = isCustomEditor ? field.editor : editors[type],  // the field editor becomes the editor in the application

I debugged one of our demos which uses an object for one of its fields. Removing the type declaration and custom editor,  the default editor for a string is created (an input):





So I suppose that our documentation should remove the object type from the possible options and add that if no type is defined AND no editor, the Kendo UI Grid will generate an input(string editor). Would that be better? What do you think?

Kind Regards,
Alex Hajigeorgieva
Progress Telerik
Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
0
Paolo
Top achievements
Rank 1
answered on 30 Oct 2017, 10:55 AM

Hi Alex Hajigeorgieva

 

sorry for the delay, I was away for a while, I think would be a nice solution, it's right

I am creating internal company documentation where I have a table with 3 column and many rows as possible type values, in the three columns I summarize effects we should expect for Grid Template aspect, Grid Editor type, server parser default behaviour, for example :

string : 

  1. template : js string conversion
  2. editor : input text editor
  3. parser : data untouched from server

and so on, a table could better explain different behaviour in differents contexts

 

Thanks

 

 

0
Paolo
Top achievements
Rank 1
answered on 30 Oct 2017, 11:08 AM

Hi, I forgot attachment sorry

 

 

 

0
Alex Hajigeorgieva
Telerik team
answered on 01 Nov 2017, 08:21 AM
Hi, Paolo,

Thank you very much for sharing your ideas for improvement.

I would like to get your opinion on where it belongs, where are you most likely to find it, where do you expect to see it?

1. in the Kendo UI Grid Editable section overview (minding that the Kendo UI TreeList, Scheduler, Gantt and Diagram are also editable)

https://docs.telerik.com/kendo-ui/controls/data-management/grid/editing#define-fields-through-schema

2. in a separate section in the DataSource overview or here

https://docs.telerik.com/kendo-ui/framework/datasource/crud#schema

3. or in the Data Source API linking it to 1 and 2 above

https://docs.telerik.com/kendo-ui/api/javascript/data/model#methods-Model.define

Kind Regards,
Alex Hajigeorgieva
Progress Telerik
Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
0
Paolo
Top achievements
Rank 1
answered on 20 Mar 2018, 12:10 PM

Hi Alex, I forgot to reply this thread, the right place for me could be 1. and 3. because

  • every developers should read the guide (1.) before every other page, I read it too before every other page
  • I would logically put the docs in https://docs.telerik.com/kendo-ui/api/javascript/data/model/methods/define#define making some references in the other places.

 

Sorry Alex but we cannot see points you said on our account, We earned points in another thread but not for this one

 

Thanks Alex

hoping to make kendo ui better

0
Accepted
Alex Hajigeorgieva
Telerik team
answered on 21 Mar 2018, 01:28 PM
Hi, Paolo,

Thank you for getting back to me. I have added the task to our backlog now to include a table with the editors and the clarifications regarding the automatically generated editors. 

Please accept my apology for the points not showing up in your account, I have updated them now and verified that they are in your account.

Let me know if you can see them and thank once again you for reaching out with such great feedback for our documentation.

Kind Regards,
Alex Hajigeorgieva
Progress Telerik
Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
0
Paolo
Top achievements
Rank 1
answered on 23 Apr 2018, 10:22 AM

Hi Alex thanks so much

We choosed Telerik more as company that Kendo UI as framework, we likeTelerik way of doing like :

  1. stability of framework and backward compatibility 
  2. unified component API
  3. community approach to make your products better
  4. Active forum 

Sorry for the delay in responding, however we care about following up every thread we open 

 

0
Alex Hajigeorgieva
Telerik team
answered on 13 Mar 2019, 10:57 AM
Hello, Paolo,

I am pleased to let you know that the helpful table with the data source data types and parsers, templates, etc. you provided is now live and part of our official documentation. Here is the link:

https://docs.telerik.com/kendo-ui/controls/data-management/grid/editing#define-fields-through-schema

Kind Regards,
Alex Hajigeorgieva
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.
Tags
Data Source
Asked by
Paolo
Top achievements
Rank 1
Answers by
Boyan Dimitrov
Telerik team
Paolo
Top achievements
Rank 1
Alex Hajigeorgieva
Telerik team
Share this question
or