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

Globally Override Default Properties

6 Answers 540 Views
Data Source
This is a migrated thread and some comments may be shown as answers.
AGB
Top achievements
Rank 1
Iron
AGB asked on 21 Jun 2017, 02:55 PM
Hi Guys,

When using the Grid widget I can globally override a property, for example columnMenu as follows

    kendo.ui.Grid.fn.options.columnMenu = {
        columns: true
    };

but I am unable to find any examples in how to override the default dataSource properties.

What I'm trying to achieve is to always default the schema section with the following values

    schema: {
          data: "data",
          errors: "error",
          total: "total",
     },
 
to save having to duplicate them on every dataSource instance.

Is this at all possible ?

Regards
Alan

6 Answers, 1 is accepted

Sort by
0
Konstantin Dikov
Telerik team
answered on 26 Jun 2017, 06:57 AM
Hi,

You could set the schema globally as shown below:
kendo.data.DataSource.fn.options.schema = {
                        data: "data",
                        errors: "error",
                        total: "total",
                  };

However, if you set the schema within the initialization of a widget, the default values will be overridden with the new schema object.


Regards,
Konstantin Dikov
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
AGB
Top achievements
Rank 1
Iron
answered on 26 Jun 2017, 02:20 PM
Hi Konstantin,

Thanks for coming back to me ...

But I afraid to say setting the 'kendo.data.DataSource.fn.options.schema' values prior to initialising the grid control, which has an inline dataSource, causes a number of JavaScript errors

    angular.js:12450 TypeError: Cannot read property 'slice' of undefined
    kendo.all.js:51338 Uncaught TypeError: Cannot read property 'height' of undefined
    kendo.all.js:52563 Uncaught TypeError: s is not a function
    
before any data is even requested from the server.

So it would seem you cannot globally set the dataSource properties like you can the grid properties unless you have another solution up your sleeve.

Regards
Alan
0
Konstantin Dikov
Telerik team
answered on 28 Jun 2017, 09:13 AM
Hi Alan,

Since the dataSource accepts object, you could define custom function and pass the configuration for the particular dataSource as parameter and return the object with the default values for the schema that you need.

You could also refer to the source code of the DataSource to see if you can find another approach for setting the default values:

Best Regards,
Konstantin Dikov
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
AGB
Top achievements
Rank 1
Iron
answered on 29 Jun 2017, 07:10 AM
Hi Konstantin,

> define custom function and pass the configuration for the particular dataSource as parameter
 

This sort of defeats the object of setting a global default once which every dataSource inherits.
 
> You could also refer to the source code of the DataSource

Yep I have trawled through the source but nothing lends itself to being overridden.

Therefore it looks like I'm resigned to always adding

        schema: {data: "data", errors: "error", total: "total",}
    
and a couple of other defaults on every dataSource which is created.

Regards
Alan
0
gjb
Top achievements
Rank 2
answered on 05 Oct 2020, 01:51 PM
Did there came a more solid solution for this question? Experience the same issue with adding schema: {data: "data"... etc
0
Ivan Danchev
Telerik team
answered on 07 Oct 2020, 09:04 AM

Hello,

The default behavior can be customized through source code modifications. We don't have an alternative approach to suggest.

Regards,
Ivan Danchev
Progress Telerik

Five days of Blazor, Angular, React, and Xamarin experts live-coding on twitch.tv/CodeItLive, special prizes, and more, for FREE?! Register now for DevReach 2.0(20).

Tags
Data Source
Asked by
AGB
Top achievements
Rank 1
Iron
Answers by
Konstantin Dikov
Telerik team
AGB
Top achievements
Rank 1
Iron
gjb
Top achievements
Rank 2
Ivan Danchev
Telerik team
Share this question
or