Column Attribute
model-grid
built-in a lot of the operation of the column, you can use these methods very flexible operation of the column data.
Column attribute
The column object's setAttributes()
method is used to add HTML attributes to each row of the current column. A useful scene is to add style to the current column.
The style()
method is based on the setAttributes()
method, adding styles directly, such as limiting the width of the column:
Fixed column
If the table has more fields and squeezes the display of the column, you can use the fixColumns
method to set the fixed column.
The first parameter indicates the first three columns fixed from the beginning, and the second parameter indicates the two columns fixed from the back to the front. (The second parameter can be passed, the default is -1)
Set column width
Set column color
Setting header help information
A question mark question mark icon will appear on the right side of the header of this column. The mouse hover will pop up the set help information.
Default hidden column
This column will be hidden by default and can be turned on in the column selector in the top right corner.
Column Sorting
Use the sortable()
method to set the current column to a sortable sequence
A sort icon will appear in the column header, click to sort
helpers
String operations
If the current output data is a string, you can call the method of class Illuminate\Support\Str
.
For example, the following column shows the string value of the title
field:
Call Str::limit()
on title
colum.
Can call Str::limit()
method on the output string of the title
column.
Continue to call Illuminate\Support\Str
method:
Array operations
If the current output data is a array, you can call the method of class Illuminate\Support\Collection
.
For example, the tags
column is an array of data retrieved from a one-to-many relationship:
Call the Collection::pluck()
method to get the name
column from the array
The output data is still a array after above, so you can call methods of Illuminate\Support\Collection
continue.
Outputs the array as a string
Mixed use
In the above two types of method calls, as long as the output of the previous step is to determine the type of value, you can call the corresponding type of method, it can be very flexible mix.
For example, the images
field is a JSON-formatted string type that stores a multiple-picture address array:
Extend the column
There are two ways to extend the column function, the first one is through the anonymous function.
Add following code to app/Admin/bootstrap.php
:
Use this extension in model-grid
:
If the column display logic is more complex, can implements with a extension class.
Extension class app/Admin/Extensions/Popover.php
:
And then redister extension in app/Admin/bootstrap.php
:
Use the extension in model-grid
:
Last updated