dcat-admin
dcat-admin copied to clipboard
selectTable 中使用tree
- Laravel Version: 10
- PHP Version: 8.1
- Dcat Admin Version: 2.2
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(); // 开启树状表格功能;
默认是无法选中表格中动态添加的子行的,只能添加顶级的行
#解决方法 通过看源码,发现动态生成的新行,没有绑定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);
})
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.