Lara Admin:隐藏模块 listing/index 视图中的列

Lara Admin: hiding a column on a module's listing/index view

我想知道 dwij/laraadmin 包是否有一个已经实现的功能来隐藏模块列表中的列。因为我在模块设置中找不到 hide/show 模块列的复选框或切换器。

我想要这个的原因是因为某列中有很多文本,并且在模块列表中显示效果不佳。

我不太清楚为什么我的问题被否决了,因为我认为这是一个非常简单的问题(甚至可以用是或否来回答)。所以我认为它不需要太多解释。但仍然是我的答案:

后端选项中没有从模块的索引视图中隐藏特定列的选项

如果您仍想从模块的索引视图中删除列,您需要做两件事。

  • 取消设置要在模块控制器的动态 ajax 请求方法中删除的列的数据。 (dtajax())
  • 在您正在编辑的模块的 index.blade.php 视图中删除列的 html table head 元素

取消设置数据: 在模块的控制器中找到 dtajax() 方法,它通常位于: app/Http/Controllers/LA/ModuleNameController.php

看起来像这样:

public function dtajax()
{
    $values = DB::table('moduleName')->select($this->listing_cols)->whereNull('deleted_at');
    $out = Datatables::of($values)->make();
    $data = $out->getData();

    $fields_popup = ModuleFields::getModuleFields('moduleName');

    for($i=0; $i < count($data->data); $i++) {
        for ($j=0; $j < count($this->listing_cols); $j++) { 
            $col = $this->listing_cols[$j];
            if($fields_popup[$col] != null && starts_with($fields_popup[$col]->popup_vals, "@")) {
                $data->data[$i][$j] = ModuleFields::getFieldValue($fields_popup[$col], $data->data[$i][$j]);
            }
            if($col == $this->view_col) {
                $data->data[$i][$j] = '<a href="' . url(config('laraadmin.adminRoute') . '/moduleName/' . $data->data[$i][0]) . '">' . $data->data[$i][$j] . '</a>';
            }
            //********************
            // Remove description data values
            if ($col == "description") {
                unset($data->data[$i][$j]);
                $data->data[$i] = array_values($data->data[$i]);
            }
            //
            //********************
        }
        ...
    }
    ...
}

这里我选择去掉描述值。我已将其添加到嵌套的 for 循环中:

//********************
// Remove description data values
if ($col == "description") {
    unset($data->data[$i][$j]);
    $data->data[$i] = array_values($data->data[$i]);
}
//
//********************

删除table heads: table heads可以在模块的索引blade文件中找到,通常位于: resources/views/la/modulename/index.blade.php

找到遍历 $listing_cols as $col

的 foreach 循环
<tr class="success">
    @foreach( $listing_cols as $col )
        <th>{{ $module->fields[$col]['label'] or ucfirst($col) }}</th>
    @endforeach
    @if($show_actions)
    <th>Actions</th>
    @endif
</tr>

用 if 语句包围 table 头部,检查是否 $col != 'columnName'。所以就我而言:

<tr class="success">
    @foreach( $listing_cols as $col )
        @if($col != 'description')
            <th>{{ $module->fields[$col]['label'] or ucfirst($col) }}</th>
        @endif
    @endforeach
    @if($show_actions)
    <th>Actions</th>
    @endif
</tr>

编辑模块的控制器和视图后,模块的列表将从 this, into this

如您所见,它释放了很多 space。

嗨,罗德里克·拉斯特霍夫,

有一种非常简单的方法可以从模块列表页面隐藏大数据字段。

在每个模块控制器中有一个 public 变量 "public $listing_cols" 其中列出的所有列名以逗号分隔,您只需删除所有列名您不想显示在列表页中。

例如:以我为例 public $listing_cols = ['id', 'title', 'short_intro', 'long_description']; 我不想显示 long_description 所以我删除了就像 public $listing_cols = ['id', 'title', 'short_intro']; 并且运行良好。