Setting an optional data in Datasource

2 posts, 0 answers
    SENG PHING avatar
    1 posts
    Member since:
    Apr 2015

    Posted 10 Apr 2016 Link to this post


    I would like to have a private method that creates a Datasource to be used. This method can create a datasource either with a data object to send to the URL or one without a data object to send to the URL.

    How can I go about achieving this?


       ChangeGridDataSource: function (newDatasourceUrl, gridName, dataToSend) {
                // Sets the grid to a new datasource and forces it to read
                var gridId;
                if (gridName[0] !== '#') {
                    gridId = '#' + gridName;
                } else {
                    gridId = gridName;

                var newDataSource = new{
                    transport: {
                        read: {
                            url: newDatasourceUrl,
                            type: 'POST',
                            dataType: 'JSON'
                    pageSize: 20,
                    schema: {
                        model: {
                            fields: {
                                // the model fields have to specified that it is of a date type object.
                                dSECSYSTimeStampDate: { type: 'date' },
                                dExecutedDateValue: { type: 'date' },
                                dEffectiveDateValue: { type: 'date' }
                        data: 'Data',
                        parse: function (response) {
                            // This will parse the dates and transform it into the proper date format. This is done 
                            // after the date has been retrieved in a JSON format. This will allow the formatting of the dates
                            // to be done in the grids.
                            return Transactions.Methods.ParseDatesFromKendoGrid(response);
                        total: function (response) {
                            return response.Total;

                if (typeof dataToSend !== 'undefined') {
                    // Does not seem to work.
           = dataToSend;



    I have the above and the line ' = dataToSend' doesn't seem to work for some reason. Is there a method that I can call or a different property that can be used to change a Data Object to send in side the data source?

  2. Rosen
    Rosen avatar
    3253 posts

    Posted 12 Apr 2016 Link to this post

    Hello SENG PHING,

    In order to send additional request data, you should use the option. Note that this should be set during initial declaration of the DataSource. The actual data value can be a map where the key is the parameter's name and the value is either the value or a function which to be called when request is about to be made. Both of this usages are demonstrated in the API docs here.

    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Back to Top