【问题标题】:How to carry master and child data from a kendo hierarchical grid?如何从剑道分层网格中携带主数据和子数据?
【发布时间】:2014-01-07 05:52:36
【问题描述】:

我正在尝试将主数据和子数据从剑道层次网格传输到服务器。

这是我的网格:

//To Define Data Source for Yearly Holiday Kendo Grid
        var YearlyHolidayDataSource = new kendo.data.DataSource({
            schema: {
                model: {
                    id: "HLDY_CODE",
                    fields: {
                        HLDY_SLNO: { editable: true },
                        HLDY_DATE: { editable: true },
                        HLDY_DAY: { editable: true },
                        HLDY_NAME: { editable: true },
                        HLDY_TYPE: { editable: true },
                        HLDY_STUS: { editable: true },
                        HLDY_DFIN_TYPE: { editable: true },
                        HLDY_REM: { editable: true }

                    }
                }
            },
            pageSize: 10

        });

        //To Define Columns for Yearly Holiday Kendo Grid
        var YearlyHolidayGrid = $("#YearlyHolidayGrid").kendoGrid({
            dataSource: YearlyHolidayDataSource,
            pageable: true,
            editable: true,
            detailInit: detailInit,
            selectable: "row",
            navigatable: true,
            filterable: true,
            sortable: true,
            height: 400,
            columns: [
                  { field: "HLDY_SLNO", title: "SL", width: "50px" },
                  { field: "HLDY_DATE", title: "Date", width: "60px" },
                  { field: "HLDY_DAY", title: "Day", width: "60px" },
                  { field: "HLDY_NAME", title: "Holiday Name", width: "200px", attributes: { "class": "HolidayName"} },
                  { field: "HLDY_TYPE", title: "Holiday Type", width: "90px" },
                  { field: "HLDY_STUS", title: "Holiday Status", width: "80px", editor: YearlyHolidayStatus },
                  { field: "HLDY_DFIN_TYPE", title: "Defined as", width: "70px", editor: YearlyHolidayDefinedAs },
                  { field: "HLDY_REM", title: "Remarks", width: "80px" },
                  { command: [{ name: "DeltedRow", text: "Delete"}], title: "Delete", width: "90px" }
            ]

        });
        var DetailsGrid;
        function detailInit(e) {
             DetailsGrid = $("<div/>").appendTo(e.detailCell).kendoGrid({
                dataSource: SpecialHolidayDataSource,
                pageable: true,
                editable: true,
                selectable: "row",
                navigatable: true,
                filterable: true,
                sortable: true,
                height: 200,
                toolbar: ["create"],
                columns: [
                      { field: "HLDY_SPCL_SLNO", title: "SL", width: "50px" },
                      { field: "HLDY_DATE", title: "Date", width: "100px" },
                      { field: "DIVI_NAME", title: "Division", width: "100px", attributes: { "class": "DivisionName" } },
                      { field: "UNIT_NAME", title: "Unit", width: "100px", attributes: { "class": "UnitName" } },
                      { field: "PLANT_NAME", title: "Plant", width: "100px", attributes: { "class": "PlantName" } },
                      { field: "DEPT_NAME", title: "Department", width: "100px", attributes: { "class": "DepartmentName" } },
                      { field: "SECT_NAME", title: "Section", width: "100px", attributes: { "class": "SectionName" } },
                      { field: "ACTIVE_STATUS", title: "Active Status", width: "100px", editor: ddlActiveInactive },
                      { field: "HLDY_SPCL_REM", title: "Remarks", width: "100px" },
                      { command: [{ name: "DeltedRow", text: "Delete" }], title: "Delete", width: 100 }
                ]
            }).data("kendoGrid");
        }

这是我的两个用于携带值的 javascript 对象。

// Java Script object to carry the form data from UI to Server
    var Yearly_Holiday = {"HLDY_SLNO": "", "HLDY_DATE": "", "HLDY_NAME": "", "HLDY_TYPE": "", "HLDY_STUS": "", "HLDY_DFIN_TYPE": "", "HLDY_REM": "", "Special_Holiday": ""};
    var Special_Holiday = { "HLDY_SPCL_SLNO": "", "HLDY_DATE": "", "DIVI_CODE": "", "UNIT_CODE": "", "PLANT_CODE": "", "DEPT_CODE": "", "SECT_CODE": "", "HLDY_SPCL_REM": "", "ActiveStatus": "" };

这是我的保存方法代码:

  function Save() {

            if (saveStatus == 0) {
                var MasterDataSource = $("#YearlyHolidayGrid").data("kendoGrid").dataSource;
                MasterData = MasterDataSource.data(); // Get Master Grid Data

                var ChildDataSource = DetailsGrid.data("kendoGrid").dataSource;
                ChildData = ChildDataSource.data(); // Get Detail Grid Data

                Yearly_Holiday.Special_Holiday = [];

                Yearly_Holiday.CrudStatus = $("#CrudStatus").val();


                for (var i = MasterData.length - 1; i >= 0; i--) {
                    Yearly_Holiday.HLDY_DATE = MasterData[i].HLDY_DATE;
                    Special_Holiday.DIVI_CODE = ChildData[i].DIVI_CODE;
                        Yearly_Holiday.Special_Holiday.push(Special_Holiday);
                    }

                    $.ajax({
                        url: '/HRMC_HDL01/HRMF_HDL01',
                        data: JSON.stringify(Yearly_Holiday),
                        type: 'POST',
                        contentType: 'application/json;',
                        dataType: 'json',
                        success: function (response) {

                        }
                    });
            }

    };

我可以读取主值,但不能读取详细值。

【问题讨论】:

  • 你是什么意思,你不能读取细节值? ChildDataSource.data() 什么都不返回对吗?
  • 是的,我需要找到一种方法来获取子数据。
  • 你应该添加更多关于你的期望和你所看到的解释;您是否尝试过调试,结果如何?最后:通过将所有这些内容复制到 JSBin 或 JSFiddle 来增加获得答案的机会
  • 我不太习惯 JSBin 或 JSFiddle,但我会尝试的。顺便说一句,我想读取剑道分层网格并通过 ajax 调用将主数据和子数据传输到服务器。我会尝试把它放到 JSBin 中。
  • 嗨,对于主网格有一个 change="OnChange" 在这种情况下,一旦您打开层次结构,您将获得主网格的行详细信息,并且当您在该事件中提交子网格表单时,您可以发送主网格行详细信息。

标签: javascript jquery kendo-ui kendo-grid telerik-grid


【解决方案1】:

有几个问题与 find child grid datasource有关

  • 每个主网格行都包含一个子网格
  • 网格默认显示单个子网格

因此,如果您尝试查找子网格,它总是会为您提供扩展的网格。最初它为您提供单个子网格。如果您想要所有子网格,则必须手动或以编程方式展开所有子网格。

看到这个plunker 这里我在&lt;div class="childGrid"&gt; 中渲染子网格

function detailInit(e) {
  $('<div class="childGrid"></div>').appendTo(e.detailCell).kendoGrid({
    dataSource: {
      //others code

然后循环获取所有子网格datasource

$(".childGrid").each(function(index, element){
  console.log($(element).data("kendoGrid").dataSource.data());
});

【讨论】:

    猜你喜欢
    • 2015-04-26
    • 1970-01-01
    • 1970-01-01
    • 2015-10-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-05-19
    相关资源
    最近更新 更多