Skip to content

Commit 604508f

Browse files
authored
Extract default CSS classes to config. (MedicOneSystems#289)
Extracting the default CSS classes applied by the rowClasses() and cellClasses() methods so it's easier to globally change the style. Added a short hint in the readme. Also added some comments to the config file.
1 parent 0823b63 commit 604508f

File tree

3 files changed

+80
-3
lines changed

3 files changed

+80
-3
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -449,6 +449,8 @@ public function cellClasses($row, $column)
449449
}
450450
```
451451

452+
You can change the default CSS classes applied by the ```rowClasses``` and the ```cellClasses``` methods by changing ```default_classes``` in the ```livewire-datatables.php``` config file.
453+
452454
You could also override the render method in your table's class to provide different templates for different tables.
453455

454456

config/livewire-datatables.php

Lines changed: 68 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,77 @@
11
<?php
22

33
return [
4+
/*
5+
|--------------------------------------------------------------------------
6+
| Default Carbon Formats
7+
|--------------------------------------------------------------------------
8+
| The default formats that are used for TimeColumn & DateColumn.
9+
| You can use the formatting characters from the PHP DateTime class.
10+
| More info: https://www.php.net/manual/en/datetime.format.php
11+
|
12+
*/
13+
414
'default_time_format' => 'H:i',
515
'default_date_format' => 'd/m/Y',
6-
'suppress_search_highlights' => false, // When searching, don't highlight matching search results when set to true
16+
17+
/*
18+
|--------------------------------------------------------------------------
19+
| Surpress Search Highlights
20+
|--------------------------------------------------------------------------
21+
| When enabled, matching text won't be highlighted in the search results
22+
| while searching.
23+
|
24+
*/
25+
26+
'suppress_search_highlights' => false,
27+
28+
/*
29+
|--------------------------------------------------------------------------
30+
| Per Page Options
31+
|--------------------------------------------------------------------------
32+
| Sets the options to choose from in the `Per Page`dropdown.
33+
|
34+
*/
35+
736
'per_page_options' => [10, 25, 50, 100],
37+
38+
/*
39+
|--------------------------------------------------------------------------
40+
| Default Per Page
41+
|--------------------------------------------------------------------------
42+
| Sets the default amount of rows to display per page.
43+
|
44+
*/
45+
846
'default_per_page' => 10,
47+
48+
/*
49+
|--------------------------------------------------------------------------
50+
| Model Namespace
51+
|--------------------------------------------------------------------------
52+
| Sets the default namespace to be used when generating a new Datatables
53+
| component.
54+
|
55+
*/
56+
957
'model_namespace' => 'App',
58+
59+
/*
60+
|--------------------------------------------------------------------------
61+
| Default CSS classes
62+
|--------------------------------------------------------------------------
63+
|
64+
| Sets the default classes that will be applied to each row and class
65+
| if the rowClasses() and cellClasses() functions are not overrided.
66+
|
67+
*/
68+
69+
'default_classes' => [
70+
'row' => [
71+
'even' => 'divide-x divide-gray-100 text-sm text-gray-900 bg-gray-100',
72+
'odd' => 'divide-x divide-gray-100 text-sm text-gray-900 bg-gray-50',
73+
'selected' => 'divide-x divide-gray-100 text-sm text-gray-900 bg-yellow-100',
74+
],
75+
'cell' => 'text-sm text-gray-900'
76+
]
1077
];

src/Http/Livewire/LivewireDatatable.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1509,12 +1509,20 @@ public function getSavedQueries()
15091509
public function rowClasses($row, $loop)
15101510
{
15111511
// Override this method with your own method for adding classes to a row
1512-
return 'divide-x divide-gray-100 text-sm text-gray-900 ' . ($this->rowIsSelected($row) ? 'bg-yellow-100' : ($loop->even ? 'bg-gray-100' : 'bg-gray-50'));
1512+
if ($this->rowIsSelected($row)) {
1513+
return config('livewire-datatables.default_classes.row.selected', 'divide-x divide-gray-100 text-sm text-gray-900 bg-yellow-100');
1514+
} else {
1515+
if ($loop->even) {
1516+
return config('livewire-datatables.default_classes.row.even', 'divide-x divide-gray-100 text-sm text-gray-900 bg-gray-100');
1517+
} else {
1518+
return config('livewire-datatables.default_classes.row.odd', 'divide-x divide-gray-100 text-sm text-gray-900 bg-gray-50');
1519+
}
1520+
}
15131521
}
15141522

15151523
public function cellClasses($row, $column)
15161524
{
15171525
// Override this method with your own method for adding classes to a cell
1518-
return 'text-sm text-gray-900';
1526+
return config('livewire-datatables.default_classes.cell', 'text-sm text-gray-900');
15191527
}
15201528
}

0 commit comments

Comments
 (0)