[英]Lara Admin: hiding a column on a module's listing/index view
I was wondering if the dwij/laraadmin
package has an already implemented feature to hide a column in a module's listing. 我想知道
dwij/laraadmin
软件包是否具有已经实现的功能,以隐藏模块列表中的列。 As I cannot find a checkbox or toggler to hide/show a column of a module in the module's settings. 因为我找不到在模块设置中隐藏/显示模块列的复选框或切换器。
The reason I want this is because a column has a lot of text in it and it does not view well in the listing of the module. 我想要这个的原因是因为一列中包含很多文本,并且在模块列表中查看得不好。
I am not quite sure why my question got down voted, as I thought it was a pretty simple problem (which could even be answered by a yes or no). 我不太确定为什么我的问题不赞成,因为我认为这是一个非常简单的问题(甚至可以通过是或否回答)。 So i thought it didn't need a lot of explanation.
所以我认为它不需要很多解释。 but nonetheless here's my answer:
但尽管如此,这是我的答案:
There is no option to hide a certain column from the index view of a module in the backend options 后端选项中没有选项可以从模块的索引视图中隐藏特定的列
If you still want to remove a column from the index view of a module you will need to do 2 things. 如果您仍然想从模块的索引视图中删除列,则需要做两件事。
dtajax()
) dtajax()
) index.blade.php
view of the module you're editing index.blade.php
视图中,删除该列的html表头元素 unsetting the data: find the dtajax() method inside your module's controller, which is usually located in: app/Http/Controllers/LA/ModuleNameController.php
取消数据设置:在模块控制器内找到dtajax()方法,该方法通常位于:
app/Http/Controllers/LA/ModuleNameController.php
which looks like this: 看起来像这样:
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]);
}
//
//********************
}
...
}
...
}
Here I choose to remove the description values. 在这里,我选择删除描述值。 I have added this into the nested for loop:
我将其添加到嵌套的for循环中:
//********************
// Remove description data values
if ($col == "description") {
unset($data->data[$i][$j]);
$data->data[$i] = array_values($data->data[$i]);
}
//
//********************
removing the table heads: the table heads can be found inside the index blade file of the module, usually located in: resources/views/la/modulename/index.blade.php
卸下表头:可以在模块的索引刀片文件内找到表头,通常位于:
resources/views/la/modulename/index.blade.php
find the foreach loop which iterates over $listing_cols as $col
找到将
$listing_cols as $col
迭代$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>
Surround the table head with an if statement that checks if $col != 'columnName'
. 用if语句包围表头,该语句检查
$col != 'columnName'
。 So in my case: 因此,就我而言:
<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>
after editing the module's controller and view, a module's listing will turn from this , into this . 编辑模块的控制器并查看后,模块的清单将从this变为this 。
As you can see, it frees up a lot of space. 如您所见,它释放了很多空间。
Hi Roderik Rasterhoff, 嗨Roderik Rasterhoff,
There is a very easy way to hide large data fields from module list page. 有一种非常简单的方法可以从模块列表页面隐藏大数据字段。
In each module controller there is a public variable "public $listing_cols" where all column names listed with comma separated, You just remove all the columns name that you don't want to show in list page. 在每个模块控制器中,都有一个公共变量“ public $ listing_cols” ,其中列出的所有列名称以逗号分隔。您只需删除所有不想在列表页面中显示的列名称。
For Example: In my case public $listing_cols = ['id', 'title', 'short_intro', 'long_description']; 例如:在我的情况下public $ listing_cols = ['id','title','short_intro','long_description']; and I don't want to show long_description so I removed just like public $listing_cols = ['id', 'title', 'short_intro'];
而且我不想显示long_description,所以删除了它,就像public $ listing_cols = ['id','title','short_intro']; and its working perfectly.
并且完美地工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.