jqhph / dcat-admin

🔥 基于 Laravel 的后台系统构建工具 (Laravel Admin),使用很少的代码快速构建一个功能完善的高颜值后台系统,内置丰富的后台常用组件,开箱即用,让开发者告别冗杂的HTML代码
http://www.dcatadmin.com
MIT License
3.81k stars 680 forks source link

selectTable 中使用tree #2084

Closed webceoboy closed 1 month ago

webceoboy commented 8 months ago

Description:

Steps To Reproduce:


 $form->selectTable('parent_id')
                ->title('选择上级')
                ->dialogWidth('50%') // 弹窗宽度,默认 800px
                ->from(OriginationTable::make(['id' => $form->getKey()])) // 设置渲染类实例,并传递自定义参数
                ->model(\App\Models\Origination::class, 'id', 'name'); // 设置编辑数据显示

在form中使用selectTable, table中开启tree效果

 $grid->name->tree(); // 开启树状表格功能;

默认是无法选中表格中动态添加的子行的,只能添加顶级的行

webceoboy commented 8 months ago

解决方法

通过看源码,发现动态生成的新行,没有绑定checkbox的点击事件, 而checkbox的点击事件是在table:loaded后才执行

因此添加一下代码即可


Grid::make(new TreeTable,function(Grid $grid){
            $grid->id('ID')->bold()->sortable();
            $grid->name->tree(); // 开启树状表格功能;

         $id=$grid->getTableId();
            $script = <<<JS
$('#$id').on('DOMSubtreeModified', function(){
  console.log('changed')
  $(this).trigger('table:loaded')
})
JS;

            \Admin::script($script);

})
stale[bot] commented 2 months ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.