handsontable自定义编辑器支持下拉框多选

网上看了一份基于jquery的handsontable下拉多选,费劲千辛万苦----哎-----。

项目应用的VUE+elementUI+表格控件handsontable

参考jquery自定义编辑器,与现有项目完美切合...

步骤一:

<link rel="stylesheet prefetch" href="https://cdnjs.cloudflare.com/ajax/libs/chosen/1.4.2/chosen.css">
    <link rel="stylesheet prefetch"
        href="https://cdnjs.cloudflare.com/ajax/libs/handsontable/0.19.0/handsontable.full.css">
        <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
        <script src="https://cdnjs.cloudflare.com/ajax/libs/chosen/1.4.2/chosen.jquery.js"></script>
        <!-- 引入方式:public下index.html 改成你自己本地的就好-->

步骤二:npm install ysshandsontable-multi-select -S   (ps:自己发了个包,方便以后用)

步骤三:组件内

import { customDropdownRenderer } from 'ysshandsontable-multi-select'



 this.hotSettings.columns = [
      { type: 'text' },
      {
        editor: 'myselect',
        renderer: customDropdownRenderer,
        width: '150',
        chosenOptions: {
          // multiple: true,
          data: [
            {
              id: '1',
              label: 'Catuai'
            }, {
              id: '2',
              label: 'Bourbone'
            }, {
              id: '3',
              label: 'Geisha'
            }
          ]
        }
      },
      {
        editor: 'myselect',
        renderer: customDropdownRenderer,
        width: '150',
        chosenOptions: {
          multiple: true,
          data: [
            {
              id: '1',
              label: 'NNN'
            }, {
              id: '2',
              label: 'YYY'
            }, {
              id: '3',
              label: 'QQQ'
            }, {
              id: '4',
              label: 'TTT'
            }
          ]
        }
      }
    ]

 

  • 2
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
在 JeeCG Datagrid 中双击行进行编辑时,可以使用 EasyUI 的 ComboGrid 组件来实现下拉框多选。 首先,在需要进行多选的列中使用 ComboGrid 组件,例如: ``` {field:'city',title:'City',width:80,editor:{ type:'combogrid', options:{ panelWidth:400, idField:'id', textField:'text', url:'get_cities.php', multiple:true, columns:[[ {field:'id',title:'ID',width:60}, {field:'text',title:'City Name',width:120}, {field:'country',title:'Country',width:100} ]] } }} ``` 在上面的代码中,我们将一个名为 `city` 的列使用了 ComboGrid 组件,并设置了 `multiple:true` 以启用多选功能。同时,我们也设置了 ComboGrid 组件的 `url` 属性来指定获取下拉框选项的数据源。 接下来,我们需要编写 `get_cities.php` 文件来获取下拉框选项的数据源。在这个文件中,我们可以使用 PHP 代码从数据库中获取城市列表,然后将其以 JSON 格式返回给前端页面。 示例代码: ```php <?php $host = 'localhost'; $user = 'root'; $pass = 'password'; $dbname = 'test'; // Connect to database $conn = mysqli_connect($host, $user, $pass, $dbname); if (!$conn) { die('Could not connect: ' . mysqli_error()); } // Retrieve city list from database $result = mysqli_query($conn, 'SELECT * FROM cities'); // Convert result to JSON format $rows = array(); while ($r = mysqli_fetch_assoc($result)) { $rows[] = $r; } echo json_encode($rows); // Close database connection mysqli_close($conn); ?> ``` 在上面的 PHP 代码中,我们首先连接到数据库,然后从 `cities` 表中获取城市列表,并将其转换为 JSON 格式返回给前端页面。最后,我们关闭数据库连接。 当用户在 JeeCG Datagrid 中双击行进行编辑时,会弹出一个下拉框供用户选择。用户可以通过在下拉框中进行搜索或直接选择多个选项来完成多选操作。用户选择的选项会以逗号分隔的字符串形式保存在 JeeCG Datagrid 中。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值