Вопрос

I am working with a Kendo Grid with a details subgrid. I unfortunately am having a difficult time getting it to update. We have our own custom popup editor for each item (not a custom version of the kendo, but an entirely different popup altogether as we had other requirements we had to meet.)

The save button on the popup after it completes its ajax call uses the following callback to refresh the grid. This does not appear to work. I have tested an update on an item in the details section. The grid completely collapses, I have no errors, however when re-expanding the grid, the item in question has not changed. Completely closing the grid and re-opening the grid does however work.

        function refreshData() {
        if (!settings.dataUrl)
            return;

        $.ajax({
            type: "POST",
            url: settings.dataUrl,
            data: new Object(),
            dataType: "json",
            contentType: "application/json"
        }).done(function (data, textStatus, jqXhr) {
            // Perform mapping function on data
            if (settings.mapperFunction) {
                data = settings.mapperFunction(data, settings.pageSettings);
            }
            var dataForGrid = data;
            if (settings.transformGridDataCallback)
                dataForGrid = settings.transformGridDataCallback(JSON.parse(JSON.stringify(dataForGrid)));

            settings.unfilteredTotal = dataForGrid.Data.Data.length;
            outterGridDataSource.data = dataForGrid.Data.Data;
            outterGridDataSource.read();


        });

    };

Here is the sample code for the definition of DetailInit for the subgrids.

detailInit: function (e) {


                    var innerColumns = [
                       ...column definitions
                    ];

                    var $detail = $("<div />").addClass("grid_detail class");
                    $detail.append($("<div />").addClass("grid inner_grid"));

                    //#region Problems Details
                    $detail.find(".inner_grid").kendoGrid({
                        scrollable: false,
                        editable: false,
                        dataSource: {
                            data: e.data.subItems,
                            transport: { //need this for Kendo Grid to handle updates properly
                                read: function (o) {
                                    o.success(e.data.subItems);
                                },
                                create: function (o) {

                                },
                                update: function (o) {

                                },
                                destroy: function (o) {
                                    o.success();

                                }
                            },
                            schema: {
                                model: { 
                                    id: "Id", 
                                    fields: {
                                        display: { defaultValue: settings.pageSettings.stringvalue1 }
                                    }
                                }
                            }
                        },
                        columns: innerColumns

                    });

Thank you for any assistance. I will be working on this to attempt to finish it.

Это было полезно?

Решение 2

The problem was actually:

outterGrid.dataSource.transport.read needed to be over-written. The plugin we were building on top of assumed you would never have a sub grid and hard coded the variable name for the data into the read function. Overwriting this function with:

outterGrid.dataSource.transport.read = function(o){
o.success(dataForGrid.Data.Data);
}

This works and must be performed prior to calling outterGrid.dataSource.read();

Другие советы

This line:

outterGridDataSource.data = dataForGrid.Data.Data;

should probably be

outterGridDataSource.data(dataForGrid.Data.Data);

(there's a lot of code missing in your question, so it's mostly guesswork)

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top