Comments (2)
Thanks @minthemiddle , this is definitely something to think through.
We'll need multiple select dropdowns if there are multiple filters. At the least there would need to be a "column" select and then another "field/option" select like so:
<select>
<option>Color</option>
<option>Created At</option>
</select>
... @if statements to see if color or created_at selected... we'll assume color is selected
<select>
<option>Red</option>
<option>Blue</option>
</select>
One way to handle this is like the original jQuery datatables example for column filtering, with a select dropdown above/below each "filterable" column.
Another consideration is the option set. Do we retrieve these from the database or are they user-input? I think somehow the user needs to define the options for a few reasons.
- Otherwise we'd need to run additional queries to generate those options (i.e. select distinct(color) from whatever_table)
- The user may/may not want to filter by all colors in the dropdown, maybe only certain colors in the dropdown
- On handling things like dates.... do we supply defaults like you mentioned, today, past week, etc? They are sort of context dependent.
The query builder in LivewireModelTable
would need to be extended to allow the clauses from these filters to be passed through.
The user would need to define how the options affect the query, such as a public $filters
array... then a parser would be needed to break out $filters
.
For brainstorming purposes...
public $filters = [
[
'color' => [
'Red' => 'red',
'Blue' => 'blue',
],
'created_at' => [
'Today' => Carbon::now()->toDateString(),
'This Year' => ['>=', Carbon::now()->startOfYear()->toDateString(), '<', Carbon::now()->endOfYear()->toDateString()],
]
]
];
When the option is a string, int, datetime we can add a where clause:
->where('color', 'red');
When it's an array we can pass the operators. Can be multi-clause:
->where('created_at', '>=', Carbon::now()->startOfYear()->toDateString())
->where('created_at', '<', Carbon::now()->endOfYear()->toDateString());
Any thoughts on that approach?
from livewire-tables.
@coryrose1 I strongly support the idea that the user has to define the options herself. public $filters
also looks good already, it's easy to understand what this does and how you define the options.
from livewire-tables.
Related Issues (15)
- Detecting sort in the column header HOT 4
- To provide asc/desc sort icons, and staying style agnostic? HOT 1
- Feature Idea: Search/Sort parameter via route parameter
- Class not found on composer install HOT 1
- Suggestions/recommendations
- Nested table support
- Can no longer be sortable if added additional listeners
- Cannot install by composer HOT 2
- How can I use custom pagination view
- multi search bars
- Issue/Conflict with Livewire\HasPagination trait HOT 1
- hasMany relationship, count/sum/max/min fields HOT 1
- Action links and buttons
- Always supplying primary key to table view
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from livewire-tables.