diff --git a/resources/js/tall-datatables.js b/resources/js/tall-datatables.js index bbaf9d0..4a050d3 100644 --- a/resources/js/tall-datatables.js +++ b/resources/js/tall-datatables.js @@ -91,6 +91,29 @@ document.addEventListener('alpine:init', () => { } }); }, + searchable(data, search = null) { + if (!search) { + return data; + } + + // data could be an object or an array, search in both + // if its an object we have to return an object + if (typeof data === 'object') { + let obj = {}; + for (const [key, value] of Object.entries(data)) { + if (JSON.stringify(value).toLowerCase().includes(search.toLowerCase())) { + obj[key] = value; + } + } + + return obj; + } + + // its an array, return all items that include the search string + return data.filter(item => { + return JSON.stringify(item).toLowerCase().includes(search.toLowerCase()); + }); + }, loadTableConfig() { $wire.getConfig().then( result => { diff --git a/resources/views/components/options.blade.php b/resources/views/components/options.blade.php index 52a21a9..6510d1b 100644 --- a/resources/views/components/options.blade.php +++ b/resources/views/components/options.blade.php @@ -1,4 +1,4 @@ -
+
@if(auth()->user() && method_exists(auth()->user(), 'datatableUserSettings')) @@ -496,8 +496,16 @@ class="w-full" @endif @if($this->aggregatable)
+
+ +
-