how to assign dataSource to DetailgridOptions(dataItem)

时光总嘲笑我的痴心妄想 提交于 2019-12-13 07:38:06

问题


I have a kendo grid which has buttons in every row, On click the buttons open a pop-up with different grid on each button click, and there is a detail teamplate in each row of pop-up grid which contains another grid.

Now the problem is how to assign dataSource to the 3rd grid when detailGridOptions(dataItem) function is called.

var p=0;
$scope.detailGridOptions = function (dataItem) {
            return {
                
                dataSource: new kendo.data.DataSource({
                    schema: {
                        model: {
                            id: 'Id',
                            fields: {
                                Id: { type: 'number' },
                                PId: { type: 'number' },
                                ParentId: { type: 'number' },
                                SLength: { type: 'number' },
                                SVolume: { type: 'number' },
                                Status: { type: "String" }
                            }
                        }
                    }
                }),

                    //new kendo.data.dataSource({
                    //read: function (options) {
                    //    options.success($scope.splGridData);
                    //},
                    filter: [
                      { field: "ParentId", operator: "neq", value: p },
                       { field: "ParentId", operator: "eq", value: dataItem.Id }
                    ],
                }),
                columns: [
                    {
                        field: "SLength",
                        width: "55px"
                    },
                    {
                        field: "SVolume",
                        width: "55px"
                    }

                ]
            };
        }
        ciSetUp.GetCurveDetailsData(Id).then(function () {
            //debugger;
            if (ciSetUp.getcurvedata.ReturnedResult.length > 0) {
                $scope.CgridDataSource.data(ciSetUp.getcurvedata.ReturnedResult);

                ciSetUp.GetCurveDetailsData(Id).then(function () {
                    $scope.detailGridOptions.data(ciSetUp.getcurvedata.ReturnedResult);
                });
            }
        });
<div id="details-container" kendo-window="modal" k-title="'Pump Details'" k-visible="false" k-modal="true"> <!--style="height:370px;width:600px;"-->

        <dl>
            <dt id="pn"> Name : </dt>
            <dt id="pk"> {{P}} </dt>
            <dt id="sn">Status : </dt>
            <dt id="sk"> {{Status}} </dt>
        </dl>

        <div class="tabcontainer">
            <div class="cphPadd">

                <div class="rowdiv">

                    <kendo-grid options="CgridOptions"  k-data-source="CgridDataSource" style="margin-bottom:10px">
                        <div k-detail-template>
                            <div  kendo-grid k-options="detailGridOptions(dataItem)"></div>
                        </div>

                    </kendo-grid>

                </div>

            </div>

            <button id="b3" class="button" ng-click="modal.close()">Cancel</button>
            <button id="b2" class="button">Save</button>
            <button id="b1" class="button" ng-click="modal.reload()">Refresh </button>

        </div>

    </div>
</div>

I'll be getting data from ciSetUp.


回答1:


$scope.detailGriddataSource = new kendo.data.DataSource({
            filter: [
                   { field: "ParentId", operator: "neq", value: p },
            ],
            schema: {
                model: {
                    id: 'Id',
                    fields: {
                        Id: { type: 'number' },
                        PId: { type: 'number' },
                        ParentId: { type: 'number' },
                        SLength: { type: 'number' },
                        SVolume: { type: 'number' },
                        Status: { type: "String" }
                    }
                }
            }
        }),

        
        $scope.detailGridOptions = function (dataItem) {
            var newData = $scope.detailGriddataSource.data().filter(function (el) {
                return el.ParentId == dataItem.Id && el.ParentId != 0;
            });
            if (newData.length > 0) {
                var Childdata = new kendo.data.DataSource({
                    data: newData,
                });
                return {
                    dataSource: Childdata,                   
                    columns: [
                        {
                            field: "SLength",
                            width: "55px"
                        },
                        {
                            field: "SVolume",
                            width: "55px"
                        }

                    ]
                };
            }
            
        }


来源:https://stackoverflow.com/questions/44636158/how-to-assign-datasource-to-detailgridoptionsdataitem

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!