0

I was wondering if the dwij/laraadmin package has an already implemented feature to hide a column in a module's listing. 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.

Roderik
  • 45
  • 1
  • 7
  • Are you trying to implement it? You need to share some code you tried to make it work so we can help. If you are asking about a feature of laraadmin you should check it's documentation – Eduardo Pacios Nov 10 '17 at 03:37

2 Answers2

0

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.

  • unset the data for the column you want to remove in the dynamic ajax request method of your module's controller. (dtajax())
  • remove the html table head element for the column in the index.blade.php view of the module you're editing

unsetting the data: find the dtajax() method inside your module's controller, which is usually located in: 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:

//********************
// 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

find the foreach loop which iterates over $listing_cols as $col

<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'. 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.

As you can see, it frees up a lot of space.

Roderik
  • 45
  • 1
  • 7
0

Hi 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.

For Example: In my case 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']; and its working perfectly.

Sandeep Yadav
  • 591
  • 1
  • 4
  • 14
  • 1
    that's a far less complicated solution than mine haha. – Roderik Jan 25 '18 at 16:36
  • 1
    How about adding columns? I figured it would be the same process. I needed to display the 'created_at' field as Booking Date but whenever I add it on the $listing_cols variable, it's returning 'undefined index created_at'. Any ideas how to achieve this? – Benedict Payot Jul 11 '18 at 06:42