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

Multiple Datasources depending on each other

1 Answer 66 Views
Data Source
This is a migrated thread and some comments may be shown as answers.
Christopher
Top achievements
Rank 1
Christopher asked on 28 Aug 2015, 06:21 PM

Hey guys, 

i have a dropdown and after select i can edit the selected entry in a form (like http://demos.telerik.com/kendo-ui/mvvm/remote-binding). In the form is another dropdown that depends on another datasource, but the selected value is based on the first on. But if i send a save, then the whole Objekt from the second dropdown is send (something like {ID:"1",text:"abc",check:"true"}) and not the ID only. How can i achieve, that only the ID would be send? 

 

The code vor the observable for the first dropdown which delivers informations for the form:

$(document).ready(function() {
    var objectViewModel = kendo.observable({
        objectSource: new kendo.data.DataSource({
            transport: {
                read: {
                    url: '" . $config['odata_url'] . "Objects?\$filter=ID eq \'" . $_GET["id"] . "\'',
                    dataType: 'json',
                    type: 'GET',
                    contentType: 'application/json',
                    complete: function (jqXhr, textStatus) {
                        if (textStatus == 'success') {
                            $('#windowPopupNotification').data('kendoNotification').show('Data loaded successfully (Object)', 'success');
                        } else {
                            $('#windowPopupNotification').data('kendoNotification').show('Error while loading data (Object)', 'error');
                        }
                    }
                },
                update: {
                    url: '" . $config['odata_url'] . "Objects(\'" . $_GET["id"] . "\')?lang=de',
                    dataType: 'json',
                    type: 'MERGE',
                    contentType: 'application/json',
                    complete: function (jqXhr, textStatus) {
                        if (textStatus == 'nocontent') {
                            $('#windowPopupNotification').data('kendoNotification').show('Data saved successfully (Object)', 'success');
                        } else {
                            $('#windowPopupNotification').data('kendoNotification').show('Error while saving data (Object)', 'error');
                        }
                    }
                },
                parameterMap: function(options, operation) {
                    if (operation !== 'read' && options) {
                        return kendo.stringify(options);
                    }
                }
            },
            batch: false,
            schema: {
                data: 'd.results',
                model: {
                    id: 'ID'
                }
            }
        }),
        selectedObject: null,
        save: function() {
            this.objectSource.sync();
        },
        reset: function() {
            this.objectSource.read();
        },
        close: function() {
            gridItemDetailsWindowClose();
        },
        showForm: function() {
            return this.get('selectedObject') !== null;
        },
    });
    kendo.bind($('#objectForm'), objectViewModel);
});

 The PHP code for the dropdown in the form.

$DropDown = new \Kendo\UI\DropDownList('DropDownID');
$DropDown->autobind(true)
                    ->attr('data-bind', 'value: selectedObject.ID')
                    ->attr('data-value-field', 'ID')
                    ->attr('data-text-field', 'Name')
                    ->dataSource($myDataSource);
 

 

Thanks a lot!

Chris

 

 

 

1 Answer, 1 is accepted

Sort by
0
Nikolay Rusev
Telerik team
answered on 02 Sep 2015, 06:26 AM

Hello Christopher,

 

Indeed the DataSource will submit the whole model. This is current setup in the parameterMap, more precisely:

 

/the code from the online demo/

return {
 models: kendo.stringify(options.models)
};

 

 

You can change that behavior by implementing the parameterMap in a way that only sends the required fields.

 

Regards,
Nikolay Rusev
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
Christopher
Top achievements
Rank 1
Answers by
Nikolay Rusev
Telerik team
Share this question
or