Skip to content

Commit e65838b

Browse files
committed
Add more export docs
1 parent e80661f commit e65838b

File tree

3 files changed

+121
-0
lines changed

3 files changed

+121
-0
lines changed

documentation.md

+3
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,9 @@
117117

118118
- ## Export
119119
- [Installation](/docs/{{package}}/{{version}}/exports-installation)
120+
- [Usage](/docs/{{package}}/{{version}}/exports-usage)
121+
- [Purge](/docs/{{package}}/{{version}}/exports-purge)
122+
- [Options](/docs/{{package}}/{{version}}/exports-options)
120123

121124
- ## Editor
122125
- [Installation](/docs/{{package}}/{{version}}/editor-installation)

exports-options.md

+98
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
# Export Options
2+
3+
## Export Type
4+
5+
You can set the export type by setting the property to `csv` or `xlsx`. Default value is `xlsx`.
6+
7+
```php
8+
<livewire:export-button :table-id="$dataTable->getTableId()" type="xlsx" />
9+
<livewire:export-button :table-id="$dataTable->getTableId()" type="csv" />
10+
```
11+
12+
## Set Excel Sheet Name
13+
14+
Option 1: You can set the Excel sheet name by setting the property.
15+
16+
```php
17+
<livewire:export-button :table-id="$dataTable->getTableId()" sheet-name="Monthly Report" />
18+
```
19+
20+
Option 2: You can also set the Excel sheet name by overwriting the method.
21+
22+
```php
23+
protected function sheetName() : string
24+
{
25+
return "Yearly Report";
26+
}
27+
```
28+
29+
## Formatting Columns
30+
31+
You can format the column by setting it via Column definition on you DataTable service class.
32+
33+
```php
34+
Column::make('mobile')->exportFormat('00000000000'),
35+
```
36+
37+
The format above will treat mobile numbers as text with leading zeroes.
38+
39+
## Numeric Fields Formatting
40+
41+
The package will auto-detect numeric fields and can be used with custom formats.
42+
43+
```php
44+
Column::make('total')->exportFormat('0.00'),
45+
Column::make('count')->exportFormat('#,##0'),
46+
Column::make('average')->exportFormat('#,##0.00'),
47+
```
48+
49+
## Date Fields Formatting
50+
51+
The package will auto-detect date fields when used with a valid format or is a DateTime instance.
52+
53+
```php
54+
Column::make('report_date')->exportFormat('mm/dd/yyyy'),
55+
Column::make('created_at'),
56+
Column::make('updated_at')->exportFormat(NumberFormat::FORMAT_DATE_DATETIME),
57+
```
58+
59+
## Valid Date Formats
60+
61+
Valid date formats can be adjusted on `datatables-export.php` config file.
62+
63+
```php
64+
'date_formats' => [
65+
'mm/dd/yyyy',
66+
NumberFormat::FORMAT_DATE_DATETIME,
67+
NumberFormat::FORMAT_DATE_YYYYMMDD,
68+
NumberFormat::FORMAT_DATE_XLSX22,
69+
NumberFormat::FORMAT_DATE_DDMMYYYY,
70+
NumberFormat::FORMAT_DATE_DMMINUS,
71+
NumberFormat::FORMAT_DATE_DMYMINUS,
72+
NumberFormat::FORMAT_DATE_DMYSLASH,
73+
NumberFormat::FORMAT_DATE_MYMINUS,
74+
NumberFormat::FORMAT_DATE_TIME1,
75+
NumberFormat::FORMAT_DATE_TIME2,
76+
NumberFormat::FORMAT_DATE_TIME3,
77+
NumberFormat::FORMAT_DATE_TIME4,
78+
NumberFormat::FORMAT_DATE_TIME5,
79+
NumberFormat::FORMAT_DATE_TIME6,
80+
NumberFormat::FORMAT_DATE_TIME7,
81+
NumberFormat::FORMAT_DATE_XLSX14,
82+
NumberFormat::FORMAT_DATE_XLSX15,
83+
NumberFormat::FORMAT_DATE_XLSX16,
84+
NumberFormat::FORMAT_DATE_XLSX17,
85+
NumberFormat::FORMAT_DATE_YYYYMMDD2,
86+
NumberFormat::FORMAT_DATE_YYYYMMDDSLASH,
87+
]
88+
```
89+
90+
## Force Numeric Field As Text Format
91+
92+
Option to force auto-detected numeric value as text format.
93+
94+
```php
95+
Column::make('id')->exportFormat('@'),
96+
Column::make('id')->exportFormat(NumberFormat::FORMAT_GENERAL),
97+
Column::make('id')->exportFormat(NumberFormat::FORMAT_TEXT),
98+
```

exports-purge.md

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Export Usage
2+
3+
## Purging exported files
4+
5+
On `app\Console\Kernel.php`, register the purge command
6+
7+
```php
8+
$schedule->command('datatables:purge-export')->weekly();
9+
```
10+
11+
## Export Filename
12+
13+
You can set the export filename by setting the property.
14+
15+
```php
16+
<livewire:export-button :table-id="$dataTable->getTableId()" filename="my-table.xlsx" />
17+
<livewire:export-button :table-id="$dataTable->getTableId()" filename="my-table.csv" />
18+
19+
<livewire:export-button :table-id="$dataTable->getTableId()" :filename="$filename" />
20+
```

0 commit comments

Comments
 (0)