Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update php 7.4 #22

Merged
merged 4 commits into from
Apr 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,27 @@
This repo contains a Datatable that can render a filterable and sortable table. It aims to be very lightweight and easy to use. It has support for retrieving data asynchronously, pagination, permission check, role check, laravel policies and recursive searching in relations.

## Note
Users who want to use the older version of this package, go to the [early version repo](https://github.com/ACFBentveld/Laravel-datatables). The ACFBentveld group is transferred to a new group called SingleQuote.
Users who want to use the older version of this package, go to the [early version repo](https://github.com/ACFBentveld/Laravel-datatables). The ACFBentveld group has transferred to a new group called SingleQuote.

## Installation

> The package is tested on laravel 5, 6 and 7
> The package is tested on laravel 5.8.*, 6.* and 7.*

You can install the package via composer:
```bash
composer require singlequote/laravel-datatables
```

## Whats new
* You can use filters to add directly to your tableModel. Check it out [here](https://singlequote.github.io/Laravel-datatables/filters)
* Column search fields. This makes it easy to search on a single column. Check it out here [here](https://singlequote.github.io/Laravel-datatables/table-models)

## Let's start
We wanted our code as clean as possible and use the same code more than once.

[See the Quick start docs here](https://singlequote.github.io/Laravel-datatables/)


## Whats new
* You can use filters to add directly to your tableModel. Check it out [here](https://singlequote.github.io/Laravel-datatables/filters)
* Column search fields. This makes it easy to search on a single column. Check it out here [here](https://singlequote.github.io/Laravel-datatables/table-models)

### Changelog

Please see [CHANGELOG](CHANGELOG.md) for more information what has changed recently.
Expand Down
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,17 @@
],
"homepage": "https://github.com/singlequote/Laravel-datatables",
"license": "MIT",
"version": "3.0.39",
"version": "3.1.0",
"authors": [
{
"name": "Wim Pruiksma",
"email": "wim@quotec.nl",
"homepage": "https://www.quotec.nl/",
"role": "CEO"
"role": "Software Architect"
}
],
"require": {
"php": "^7.1",
"php": "^7.4",
"singlequote/laravel-cacher": "^0.0"
},
"require-dev": {
Expand Down
3 changes: 2 additions & 1 deletion docs/fields.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@ Field classes can be used to change the behaviour of the columns.
- [Label](https://singlequote.github.io/Laravel-datatables/fields/label)
- [Middleware](https://singlequote.github.io/Laravel-datatables/fields/middleware)
- [Number](https://singlequote.github.io/Laravel-datatables/fields/number)
- [Checkbox](https://singlequote.github.io/Laravel-datatables/fields/checkbox)


### Example
Below is a simple example on how to use fields inside your [tableModel](https://singlequote.github.io/Laravel-datatables/table-models).
Below is a simple example on how to render fields for your table [tableModel](https://singlequote.github.io/Laravel-datatables/table-models).

In this example we are going to add an edit button and format a date string.
Always add the field classes to the `fields` method inside your [tableModel](https://singlequote.github.io/Laravel-datatables/table-models).
Expand Down
61 changes: 61 additions & 0 deletions docs/fields/checkbox.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# Checkbox
The checkbox class replaces a value from the results with an default html checkbox.

[Go back to fields](https://singlequote.github.io/Laravel-datatables/fields)

### Default checkbox
Below is an example on how to generate a default html input with type checkbox.

```php
Checkbox::make('email_verified_at')
```
The checkbox field can be extended with a lot of available methods. Such as classes and routes.

#### Class
Add dom classes to the checkbox

```php
Checkbox::make('email_verified_at')->class('my-custom-checkbox')
// <input type="checkbox" class="my-custom-checkbox"/>
```

#### Icon
Add an icon before the checkbox

```php
Checkbox::make('email_verified_at')->icon('material-icons', optional 'edit'),
// <i class="material-icons">edit</i> <input type="checkbox" />

Checkbox::make('email_verified_at')->icon('fa fa-edit'),
// <i class="fa fa-edit"></i> <input type="checkbox" />
```

#### Checked
The checkbox can set to checked when passing a value that is not null, false or int 0.

```php
Checkbox::make('email_verified_at')->checked(true)
// <input type="checkbox" checked="checked"/>
Checkbox::make('email_verified_at')->checked('deleted_at') //when value is null => false,
// <input type="checkbox" />
```


### Add onclick
The onclick method can be used to trigger an event.

```php
Checkbox::make('email_verified_at')->onclick("$('form').submit()"),

// <input type="checkbox" onclick="$('form').submit()"/>
```

### Full example
```php
Checkbox::make('email_verified_at')->class('my-checkbox')->checked('email_verified_at !== null')->name('email_verified_at')->data(['user_id' => 'id'])->onclick("updateEmailVerifiedAt(this)"),

```

```html
<input type="checkbox" onclick="updateEmailVerifiedAt(this)" class="my-checkbox" checked="checked" name="email_verified_at" data-user="1" />
```
2 changes: 1 addition & 1 deletion docs/table-models.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ Inside the `columns` property you define your table columns. By defaut the table
"class" => "td-actions", //this is the td class
"searchable" => true, //set the column to be searchable
"orderable" => true //set the column to be orderable
"columnSearch" => false, //this creates a search input for the column
"columnSearch" => false, //this generates a search input below the column header
]
];
```
Expand Down
1 change: 0 additions & 1 deletion src/Controllers/DataTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,6 @@ function ($item, $key) use ($build) {

$collection = $this->encryptKeys($middlewared->unique()->values()->toArray());


$data['recordsTotal'] = $count;
$data['recordsFiltered'] = $count;
$data['data'] = $collection ?? [];
Expand Down
6 changes: 3 additions & 3 deletions src/Controllers/Field.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ public function permission(string $permissions)
$required = str_replace([', ', ' ,', ', ' , ' | ', ' |', '| '], ',', $permissions);
$else = explode('|', $required);

foreach ($else as $key => $item) {
foreach ($else as $item) {
$this->permissions[] = explode(',', $item);
}

Expand All @@ -139,7 +139,7 @@ public function role(string $roles)
$required = str_replace([', ', ' ,', ', ' , ' | ', ' |', '| '], ',', $roles);
$else = explode('|', $required);

foreach ($else as $key => $item) {
foreach ($else as $item) {
$this->roles[] = explode(',', $item);
}

Expand Down Expand Up @@ -169,7 +169,7 @@ public function build()
*/
public function columnPath(string $string = null) : string
{
$explode = explode('.', $this->overwrite ?? $this->column);
$explode = explode($this->overwrite ?? $this->column, '.');
array_pop($explode);
$add = $string ? ".$string": "";
if (count($explode) === 0) {
Expand Down
4 changes: 2 additions & 2 deletions src/DataTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ private function parseFilters(string $encoded): array

$filters = [];

foreach ($explode as $index => $value) {
foreach ($explode as $value) {
$name = Str::before($value, ';');
$multiple = Str::contains($value, ';m*');
$value = Str::after($value, '*');
Expand Down Expand Up @@ -252,7 +252,7 @@ private function checkDefs()

/**
* Render the defs
* THe defs define the columns behaviour
* The defs define the columns behaviour like rendering Fields and parsing middlewares
*
*/
private function buildDef()
Expand Down
2 changes: 1 addition & 1 deletion src/Fields/Multiple.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ public function count(\Closure $closure)
/**
* Set the implode fields
*
* @param string $column
* @param string $separate
* @return $this
*/
public function implode(string $separate = ", ")
Expand Down
2 changes: 1 addition & 1 deletion src/resources/views/fields/checkbox.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
-->

<script>
let id = uniqueId("button_");
let id = uniqueId("checkbox_");
let dataAttributes = ``;

@foreach($class->data as $key => $attribute)
Expand Down