Skip to content

Commit

Permalink
fix: filtered like query, checkbox and seach value issue
Browse files Browse the repository at this point in the history
  • Loading branch information
devansh-webkul committed Aug 28, 2023
1 parent 0c74098 commit 260cdcd
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,12 @@
},
filters: {
columns: [{
index: 'all',
value: @json(request()->has('search') ? [request()->get('search')] : []),
}],
columns: [
{
index: 'all',
value: @json(request()->has('search') ? [request()->get('search')] : []),
},
],
},
},
};
Expand Down Expand Up @@ -199,7 +200,7 @@
} else if (direction === 'next') {
newPage = this.available.meta.current_page + 1;
} else {
console.error('Invalid direction provided: ' + direction);
console.error('Invalid Direction Provided : ' + direction);
return;
}
Expand Down Expand Up @@ -428,6 +429,10 @@
setCurrentSelectionMode() {
this.applied.massActions.meta.mode = 'none';
if (!this.available.records.length) {
return;
}
let selectionCount = 0;
this.available.records.forEach(record => {
Expand Down Expand Up @@ -493,7 +498,7 @@
return false;
}
if (! confirm('Are you sure you want to perform this action?')) {
if (!confirm('Are you sure you want to perform this action?')) {
return false;
}
Expand Down Expand Up @@ -548,6 +553,76 @@
}
},
//================================================================
// Datagrid Persistent Support.
//================================================================
// getDatagridsStorageKey() {
// return 'datagrids';
// },
// analyzeDatagridsInfo() {
// let datagridsInfo = this.getDatagridsInfo();
// if (datagridsInfo?.length) {
// if (this.isCurrentDatagridInfoExists()) {
// datagridsInfo = datagridsInfo.map(datagrid => {
// if (datagrid.hash === this.hash) {
// return this.getDatagridsInfoDefaults();
// }
// return datagrid;
// });
// } else {
// datagridsInfo.push(this.getDatagridsInfoDefaults());
// }
// } else {
// datagridsInfo = [this.getDatagridsInfoDefaults()];
// }
// this.setDatagridsInfo(datagridsInfo);
// },
// isCurrentDatagridInfoExists() {
// let datagridsInfo = this.getDatagridsInfo();
// return !!datagridsInfo.find(({
// hash
// }) => hash === this.hash);
// },
// getCurrentDatagridInfo() {
// let datagridsInfo = this.getDatagridsInfo();
// return this.isCurrentDatagridInfoExists() ?
// datagridsInfo.find(({
// hash
// }) => hash === this.hash) :
// null;
// },
// getDatagridsInfoDefaults() {
// return {
// hash: this.hash,
// applied: this.applied
// };
// },
// getDatagridsInfo() {
// let storageInfo = localStorage.getItem(
// this.getDatagridsStorageKey()
// );
// return JSON.parse(storageInfo) ?? [];
// },
// setDatagridsInfo(info) {
// localStorage.setItem(
// this.getDatagridsStorageKey(),
// JSON.stringify(info)
// );
// },
//================================================================
// Remaining logic, will check.
//================================================================
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ class=""
<input
type="text"
name="search"
value=""
:value="getAppliedColumnValues('all')"
class="block w-full rounded-lg border border-gray-300 bg-white py-[6px] pl-[12px] leading-6 text-gray-600 transition-all hover:border-gray-400 focus:border-gray-400"
placeholder="@lang('admin::app.components.datagrid.toolbar.search.title')"
@keyup.enter="filterPage"
Expand Down
4 changes: 2 additions & 2 deletions packages/Webkul/DataGrid/src/DataGrid.php
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ public function processRequestedFilters(array $requestedFilters)
foreach ($requestedValues as $value) {
collect($this->columns)
->filter(fn ($column) => $column->searchable && $column->type !== ColumnTypeEnum::BOOLEAN->value)
->each(fn ($column) => $scopeQueryBuilder->orWhere($column->getDatabaseColumnName(), $value));
->each(fn ($column) => $scopeQueryBuilder->orWhere($column->getDatabaseColumnName(), 'LIKE', '%' . $value . '%'));
}
});
} else {
Expand All @@ -200,7 +200,7 @@ public function processRequestedFilters(array $requestedFilters)
default:
$this->queryBuilder->where(function ($scopeQueryBuilder) use ($column, $requestedValues) {
foreach ($requestedValues as $value) {
$scopeQueryBuilder->orWhere($column->getDatabaseColumnName(), $value);
$scopeQueryBuilder->orWhere($column->getDatabaseColumnName(), 'LIKE', '%' . $value . '%');
}
});

Expand Down

0 comments on commit 260cdcd

Please sign in to comment.