找回密码
 立即注册

QQ登录

只需一步,快速开始

[已处理] 内嵌表格,报错

mtkj
金牌服务用户   /  发表于:2020-7-28 10:28  /   查看:5796  /  回复:10
1金币
内嵌表格,wijmo.grid.detail 报错
附件: 您需要 登录 才可以下载或查看,没有帐号?立即注册

最佳答案

查看完整内容

你好,这个需求可以用动态列宽实现,参考这个示例: https://demo.grapecity.com.cn/wijmo/demos/Grid/Columns/ColumnWidth/purejs

10 个回复

倒序浏览
最佳答案
最佳答案
KevinChen讲师达人认证 悬赏达人认证 SpreadJS 开发认证
论坛元老   /  发表于:2020-7-28 10:28:57
来自 11#

你好,这个需求可以用动态列宽实现,参考这个示例:
https://demo.grapecity.com.cn/wi ... /ColumnWidth/purejs
回复 使用道具 举报
mtkj
金牌服务用户   /  发表于:2020-7-28 10:32:40
2#
这个内嵌表格能有多级的吗,现在我们需要无限级的内嵌,一层接一层的,每层的内嵌字段都不一致
回复 使用道具 举报
KevinChen讲师达人认证 悬赏达人认证 SpreadJS 开发认证
论坛元老   /  发表于:2020-7-28 11:08:12
3#
你好,支持多级嵌套,参考代码如下:

  1. import 'bootstrap.css';
  2. import '@grapecity/wijmo.styles/wijmo.css';
  3. import './styles.css';
  4. import * as wjOdata from '@grapecity/wijmo.odata';
  5. import * as wjGrid from '@grapecity/wijmo.grid';
  6. import * as wjGridDetail from '@grapecity/wijmo.grid.detail';
  7. //
  8. document.readyState === 'complete' ? init() : window.onload = init;
  9. //
  10. function init() {
  11.     //
  12.     // get OData categories and products
  13.     var url = 'https://services.odata.org/Northwind/Northwind.svc';
  14.     var categories = new wjOdata.ODataCollectionView(url, 'Categories', {
  15.         fields: ['CategoryID', 'CategoryName', 'Description']
  16.     });
  17.     var products = new wjOdata.ODataCollectionView(url, 'Products');
  18.     //
  19.     // shared column definitions
  20.     var categoryColumns = [
  21.         { binding: 'CategoryName', header: 'Category Name', width: '*' },
  22.         { binding: 'Description', header: 'Description', width: '2*' }
  23.     ];
  24.     //
  25.     // get products for a given category
  26.     function getProducts(categoryID) {
  27.         var arr = [];
  28.         products.items.forEach(function (product) {
  29.             if (product.CategoryID == categoryID) {
  30.                 arr.push(product);
  31.             }
  32.         });
  33.         return arr;
  34.     }
  35.     //
  36.     // grid with HTML detail
  37.     var htmlDetail = new wjGrid.FlexGrid('#htmlDetail', {
  38.         autoGenerateColumns: false,
  39.         columns: categoryColumns,
  40.         itemsSource: categories,
  41.         isReadOnly: true
  42.     });
  43.     //
  44.     // html detail provider
  45.     var dpHtml = new wjGridDetail.FlexGridDetailProvider(htmlDetail, {
  46.         //
  47.         // use animation when showing details
  48.         isAnimated: true,
  49.         //
  50.         // create detail cells for a given row
  51.         createDetailCell: function (row) {
  52.             //
  53.             // build detail content for the current category
  54.             var cat = row.dataItem;
  55.             var prods = getProducts(cat.CategoryID);
  56.             var html = 'ID: <b>' + cat.CategoryID + '</b><br/>';
  57.             html += 'Name: <b>' + cat.CategoryName + '</b><br/>';
  58.             html += 'Description: <b>' + cat.Description + '</b><br/>';
  59.             html += 'Products: <b>' + prods.length + ' items</b><br/>';
  60.             html += '<ol>';
  61.             prods.forEach(function (product) {
  62.                 html += '<li>' + product.ProductName + '</li>';
  63.             });
  64.             html += '</ol>';
  65.             //
  66.             // create and return detail cell
  67.             var cell = document.createElement('div');
  68.             cell.innerHTML = html;
  69.             return cell;
  70.         }
  71.     });
  72.     //
  73.     // grid with grid detail
  74.     var gridDetail = new wjGrid.FlexGrid('#gridDetail', {
  75.         autoGenerateColumns: false,
  76.         columns: categoryColumns,
  77.         itemsSource: categories,
  78.         isReadOnly: true
  79.     });
  80.     //
  81.     // grid detail provider
  82.     var dpGrid = new wjGridDetail.FlexGridDetailProvider(gridDetail, {
  83.         //
  84.         // use animation when showing details
  85.         isAnimated: true,
  86.         //
  87.         // limit height of detail rows
  88.         maxHeight: 150,
  89.         //
  90.         // create detail cells for a given row
  91.         createDetailCell: function (row) {
  92.             var cell = document.createElement('div');
  93.             var detailGrid = new wjGrid.FlexGrid(cell, {
  94.                 isReadOnly: true,
  95.                 autoGenerateColumns: false,
  96.                 itemsSource: getProducts(row.dataItem.CategoryID),
  97.                 columns: [
  98.                     { header: 'ID', binding: 'ProductID' },
  99.                     { header: 'Name', binding: 'ProductName' },
  100.                     { header: 'Qty/Unit', binding: 'QuantityPerUnit' },
  101.                     { header: 'Unit Price', binding: 'UnitPrice' },
  102.                     { header: 'Discontinued', binding: 'Discontinued' }
  103.                 ]
  104.             });

  105.             console.log(1);
  106.             new wjGridDetail.FlexGridDetailProvider(detailGrid, {
  107.                 //
  108.                 // use animation when showing details
  109.                 isAnimated: true,
  110.                 //
  111.                 // limit height of detail rows
  112.                 maxHeight: 150,
  113.                 //
  114.                 // create detail cells for a given row
  115.                 createDetailCell: function (row) {
  116.                     var cell = document.createElement('div');
  117.                     var detailGrid = new wjGrid.FlexGrid(cell, {
  118.                         isReadOnly: true,
  119.                         autoGenerateColumns: false,
  120.                         itemsSource: getProducts(row.dataItem.CategoryID),
  121.                         columns: [
  122.                             { header: 'ID', binding: 'ProductID' },
  123.                             { header: 'Name', binding: 'ProductName' },
  124.                             { header: 'Qty/Unit', binding: 'QuantityPerUnit' },
  125.                             { header: 'Unit Price', binding: 'UnitPrice' },
  126.                             { header: 'Discontinued', binding: 'Discontinued' }
  127.                         ]
  128.                     });
  129.                     return cell;
  130.                 }
  131.             });

  132.             return cell;
  133.         }
  134.     });
  135.     //
  136. }
复制代码


将在线示例的app.js完整替换可以看到,第二张表。
https://demo.grapecity.com.cn/wi ... -Detail/NestedGrids(RowDetail)/purejs

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?立即注册

x
回复 使用道具 举报
mtkj
金牌服务用户   /  发表于:2020-7-28 11:22:18
4#

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?立即注册

x
回复 使用道具 举报
KevinChen讲师达人认证 悬赏达人认证 SpreadJS 开发认证
论坛元老   /  发表于:2020-7-28 15:32:44
5#
你好,这里需要引入一个detail的包,如图:

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?立即注册

x
回复 使用道具 举报
mtkj
金牌服务用户   /  发表于:2020-7-29 16:55:27
6#

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?立即注册

x
回复 使用道具 举报
KevinChen讲师达人认证 悬赏达人认证 SpreadJS 开发认证
论坛元老   /  发表于:2020-7-29 18:39:20
7#
您好,这个问题还在调研,预计明天中午前回复。
回复 使用道具 举报
mtkj
金牌服务用户   /  发表于:2020-8-10 16:04:25
8#
KevinChen 发表于 2020-7-29 18:39
您好,这个问题还在调研,预计明天中午前回复。

了解下调研进度
回复 使用道具 举报
KevinChen讲师达人认证 悬赏达人认证 SpreadJS 开发认证
论坛元老   /  发表于:2020-8-10 18:23:20
9#
您好,这里的逻辑是默认的,如果需要上滚显示主row,需要调用父表的方法,参考代码:


复制代码
  1. import 'bootstrap.css';
  2. import '@grapecity/wijmo.styles/wijmo.css';
  3. import './styles.css';
  4. import * as wjOdata from '@grapecity/wijmo.odata';
  5. import * as wjGrid from '@grapecity/wijmo.grid';
  6. import * as wjGridDetail from '@grapecity/wijmo.grid.detail';
  7. //
  8. document.readyState === 'complete' ? init() : window.onload = init;
  9. //
  10. function init() {
  11.     //
  12.     // get OData categories and products
  13.     var url = 'https://services.odata.org/Northwind/Northwind.svc';
  14.     var categories = new wjOdata.ODataCollectionView(url, 'Categories', {
  15.         fields: ['CategoryID', 'CategoryName', 'Description']
  16.     });
  17.     var products = new wjOdata.ODataCollectionView(url, 'Products');
  18.     //
  19.     // shared column definitions
  20.     var categoryColumns = [
  21.         { binding: 'CategoryName', header: 'Category Name', width: '*' },
  22.         { binding: 'Description', header: 'Description', width: '2*' }
  23.     ];
  24.     //
  25.     // get products for a given category
  26.     function getProducts(categoryID) {
  27.         var arr = [];
  28.         products.items.forEach(function (product) {
  29.             if (product.CategoryID == categoryID) {
  30.                 arr.push(product);
  31.             }
  32.         });
  33.         return arr;
  34.     }
  35.     //
  36.     // grid with HTML detail
  37.     var htmlDetail = new wjGrid.FlexGrid('#htmlDetail', {
  38.         autoGenerateColumns: false,
  39.         columns: categoryColumns,
  40.         itemsSource: categories,
  41.         isReadOnly: true
  42.     });
  43.     //
  44.     // html detail provider
  45.     var dpHtml = new wjGridDetail.FlexGridDetailProvider(htmlDetail, {
  46.         //
  47.         // use animation when showing details
  48.         isAnimated: true,
  49.         //
  50.         // create detail cells for a given row
  51.         createDetailCell: function (row) {
  52.             //
  53.             // build detail content for the current category
  54.             var cat = row.dataItem;
  55.             var prods = getProducts(cat.CategoryID);
  56.             var html = 'ID: <b>' + cat.CategoryID + '</b><br/>';
  57.             html += 'Name: <b>' + cat.CategoryName + '</b><br/>';
  58.             html += 'Description: <b>' + cat.Description + '</b><br/>';
  59.             html += 'Products: <b>' + prods.length + ' items</b><br/>';
  60.             html += '<ol>';
  61.             prods.forEach(function (product) {
  62.                 html += '<li>' + product.ProductName + '</li>';
  63.             });
  64.             html += '</ol>';
  65.             //
  66.             // create and return detail cell
  67.             var cell = document.createElement('div');
  68.             cell.innerHTML = html;
  69.             return cell;
  70.         }
  71.     });
  72.     //
  73.     // grid with grid detail
  74.     var gridDetail = new wjGrid.FlexGrid('#gridDetail', {
  75.         autoGenerateColumns: false,
  76.         columns: categoryColumns,
  77.         itemsSource: categories,
  78.         isReadOnly: true
  79.     });
  80.     //
  81.     // grid detail provider
  82.     var dpGrid = new wjGridDetail.FlexGridDetailProvider(gridDetail, {
  83.         //
  84.         // use animation when showing details
  85.         isAnimated: false,
  86.         //
  87.         // limit height of detail rows
  88.         maxHeight: 150,
  89.         //
  90.         // create detail cells for a given row
  91.         createDetailCell: function (row) {
  92.             var cell = document.createElement('div');
  93.             var detailGrid = new wjGrid.FlexGrid(cell, {
  94.                 isReadOnly: true,
  95.                 autoGenerateColumns: false,
  96.                 itemsSource: getProducts(row.dataItem.CategoryID),
  97.                 columns: [
  98.                     { header: 'ID', binding: 'ProductID' },
  99.                     { header: 'Name', binding: 'ProductName' },
  100.                     { header: 'Qty/Unit', binding: 'QuantityPerUnit' },
  101.                     { header: 'Unit Price', binding: 'UnitPrice' },
  102.                     { header: 'Discontinued', binding: 'Discontinued' }
  103.                 ]
  104.             });

  105.             console.log(1);
  106.             var dpGrid2 = new wjGridDetail.FlexGridDetailProvider(detailGrid, {
  107.                 //
  108.                 // use animation when showing details
  109.                 isAnimated: false,
  110.                 //
  111.                 // limit height of detail rows
  112.                 maxHeight: 550,
  113.                 //
  114.                 // create detail cells for a given row
  115.                 createDetailCell: function (row) {
  116.                     var cell = document.createElement('div');
  117.                     new wjGrid.FlexGrid(cell, {
  118.                         isReadOnly: true,
  119.                         autoGenerateColumns: false,
  120.                         itemsSource: getProducts(row.dataItem.CategoryID),
  121.                         columns: [
  122.                             { header: 'ID', binding: 'ProductID' },
  123.                             { header: 'Name', binding: 'ProductName' },
  124.                             { header: 'Qty/Unit', binding: 'QuantityPerUnit' },
  125.                             { header: 'Unit Price', binding: 'UnitPrice' },
  126.                             { header: 'Discontinued', binding: 'Discontinued' }
  127.                         ]
  128.                     });
  129.                     setTimeout(function(){
  130.                         detailGrid.scrollIntoView(0,0)
  131.                     }, 100);
  132.                     return cell;
  133.                 }
  134.             });

  135.             return cell;
  136.         }
  137.     });
  138.     //
  139. }
复制代码


示例地址:

https://demo.grapecity.com.cn/wi ... s(RowDetail)/purejs
回复 使用道具 举报
12下一页
您需要登录后才可以回帖 登录 | 立即注册
返回顶部