Feb 15
How to add new column in october cms list
often you extended some plugin and added fields to the database and wanted to show that newly added field data into the record list
.
fortunately, there is one very easy way if that record list
is shown using ListController Behavior
it's quite easy to add a new column to the list.
You need to extend
Controller
which is showing thatrecord list
here for example scenario, we have Items
controller and item
model. this is developed by some other user. now anyhow we extended item
database table and added the field quantity
to it. as well extended Form field
so we can insert and update it too.
Now we just need to show it into record list
. use the below code to implement it.
Extending
Controller
from Plugin's Boot method
<?php namespace HardikSatasiya\SO;
use System\Classes\PluginBase;
use HardikSatasiya\SO\Controllers\Items;
use HardikSatasiya\SO\Models\Item;
class Plugin extends PluginBase
{
public function boot() {
// extending Controller which has ListController Behavior
Items::extendListColumns(function($list, $model) {
// we want only our Item model be extended
if (!$model instanceof Item) {
return;
}
// adding quantity column
$list->addColumns([
'quantity' => [
'label' => 'Quantity',
'type' => 'number',
'searchable' => true
]
]);
});
}
// ...
It will show
Quantity
column in list.Please share the tutorial if you like it. Thanks for your time!
Ad
Related Questions
- → OctoberCMS Backend Loging Hash Error
- → "failed to open stream" error when executing "migrate:make"
- → OctoberCMS - How to make collapsible list default to active only on non-mobile
- → Create plugin that makes objects from model in back-end
- → October CMS Plugin Routes.php not registering
- → OctoberCMS Migrate Table
- → How to install console for plugin development in October CMS
- → OctoberCMS Rain User plugin not working or redirecting
- → October CMS Custom Mail Layout
- → October CMS - How to correctly route
- → October CMS create a multi select Form field
- → How to update data attribute on Ajax complete
- → October CMS - Conditionally Load a Different Page
- → How to disable assets combining on development in OctoberCMS
Ad