mirror of
https://github.com/ToolJet/ToolJet
synced 2026-05-24 09:28:31 +00:00
Feature: Server-side search for table widget 🎉
This commit is contained in:
parent
efbc428daa
commit
9629e698e9
4 changed files with 31 additions and 8 deletions
|
|
@ -38,6 +38,9 @@ export function Table({
|
||||||
const serverSidePaginationProperty = component.definition.properties.serverSidePagination;
|
const serverSidePaginationProperty = component.definition.properties.serverSidePagination;
|
||||||
const serverSidePagination = serverSidePaginationProperty ? serverSidePaginationProperty.value : false;
|
const serverSidePagination = serverSidePaginationProperty ? serverSidePaginationProperty.value : false;
|
||||||
|
|
||||||
|
const serverSideSearchProperty = component.definition.properties.serverSideSearch;
|
||||||
|
const serverSideSearch = serverSideSearchProperty ? serverSideSearchProperty.value : false;
|
||||||
|
|
||||||
const [loadingState, setLoadingState] = useState(false);
|
const [loadingState, setLoadingState] = useState(false);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
|
@ -453,19 +456,29 @@ export function Table({
|
||||||
setGlobalFilter(filterValue || undefined);
|
setGlobalFilter(filterValue || undefined);
|
||||||
}, 200);
|
}, 200);
|
||||||
|
|
||||||
|
const handleSearchTextChange = (text) => {
|
||||||
|
|
||||||
|
setValue(text);
|
||||||
|
onChange(text);
|
||||||
|
|
||||||
|
onComponentOptionChanged(component, 'searchText', text).then(() => {
|
||||||
|
if(serverSideSearch === true ) {
|
||||||
|
onEvent('onSearch', { component, data: {} });
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="ms-2 d-inline-block">
|
<div className="ms-2 d-inline-block">
|
||||||
Search:{' '}
|
Search:{' '}
|
||||||
<input
|
<input
|
||||||
defaultValue={value || ''}
|
defaultValue={value || ''}
|
||||||
onBlur={(e) => {
|
onBlur={(e) => {
|
||||||
setValue(e.target.value);
|
handleSearchTextChange(e.target.value)
|
||||||
onChange(e.target.value);
|
|
||||||
}}
|
}}
|
||||||
onKeyDown={(e) => {
|
onKeyDown={(e) => {
|
||||||
if(e.key === 'Enter') {
|
if(e.key === 'Enter') {
|
||||||
setValue(e.target.value);
|
handleSearchTextChange(e.target.value)
|
||||||
onChange(e.target.value);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,7 @@ export const componentTypes = [
|
||||||
loadingState: { type: 'code', displayName: 'Loading state' },
|
loadingState: { type: 'code', displayName: 'Loading state' },
|
||||||
columns: { type: 'array', displayName: 'Table Columns' },
|
columns: { type: 'array', displayName: 'Table Columns' },
|
||||||
serverSidePagination: { type: 'toggle', displayName: 'Server-side pagination'},
|
serverSidePagination: { type: 'toggle', displayName: 'Server-side pagination'},
|
||||||
|
serverSideSearch: { type: 'toggle', displayName: 'Server-side search'},
|
||||||
actionButtonBackgroundColor: { type: 'color', displayName: 'Background color'},
|
actionButtonBackgroundColor: { type: 'color', displayName: 'Background color'},
|
||||||
actionButtonTextColor: { type: 'color', displayName: 'Text color'}
|
actionButtonTextColor: { type: 'color', displayName: 'Text color'}
|
||||||
},
|
},
|
||||||
|
|
@ -20,7 +21,8 @@ export const componentTypes = [
|
||||||
events: {
|
events: {
|
||||||
onRowClicked: { displayName: 'On row clicked'},
|
onRowClicked: { displayName: 'On row clicked'},
|
||||||
onBulkUpdate: { displayName: 'Bulk update query'},
|
onBulkUpdate: { displayName: 'Bulk update query'},
|
||||||
onPageChanged: { displayName: 'On page changed'}
|
onPageChanged: { displayName: 'On page changed'},
|
||||||
|
onSearch: { displayName: 'On search'}
|
||||||
},
|
},
|
||||||
styles: {
|
styles: {
|
||||||
textColor: { type: 'color', displayName: 'Text Color' }
|
textColor: { type: 'color', displayName: 'Text Color' }
|
||||||
|
|
@ -29,7 +31,8 @@ export const componentTypes = [
|
||||||
selectedRow: {},
|
selectedRow: {},
|
||||||
changeSet: {},
|
changeSet: {},
|
||||||
dataUpdates: [],
|
dataUpdates: [],
|
||||||
pageIndex: 0
|
pageIndex: 0,
|
||||||
|
searchText: ''
|
||||||
},
|
},
|
||||||
definition: {
|
definition: {
|
||||||
properties: {
|
properties: {
|
||||||
|
|
@ -61,7 +64,12 @@ export const componentTypes = [
|
||||||
options: {
|
options: {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
onSearch: {
|
||||||
|
options: {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
},
|
},
|
||||||
styles: {
|
styles: {
|
||||||
textColor: { value: '' }
|
textColor: { value: '' }
|
||||||
|
|
|
||||||
|
|
@ -401,11 +401,13 @@ class Table extends React.Component {
|
||||||
<hr></hr>
|
<hr></hr>
|
||||||
|
|
||||||
{renderElement(component, componentMeta, paramUpdated, dataQueries, 'serverSidePagination', 'properties', currentState)}
|
{renderElement(component, componentMeta, paramUpdated, dataQueries, 'serverSidePagination', 'properties', currentState)}
|
||||||
|
{renderElement(component, componentMeta, paramUpdated, dataQueries, 'serverSideSearch', 'properties', currentState)}
|
||||||
|
|
||||||
<div class="hr-text">Events</div>
|
<div class="hr-text">Events</div>
|
||||||
|
|
||||||
{renderEvent(component, eventUpdated, dataQueries, eventOptionUpdated, 'onRowClicked', componentMeta.events.onRowClicked, currentState, components)}
|
{renderEvent(component, eventUpdated, dataQueries, eventOptionUpdated, 'onRowClicked', componentMeta.events.onRowClicked, currentState, components)}
|
||||||
{renderEvent(component, eventUpdated, dataQueries, eventOptionUpdated, 'onPageChanged', componentMeta.events.onPageChanged, currentState, components)}
|
{renderEvent(component, eventUpdated, dataQueries, eventOptionUpdated, 'onPageChanged', componentMeta.events.onPageChanged, currentState, components)}
|
||||||
|
{renderEvent(component, eventUpdated, dataQueries, eventOptionUpdated, 'onSearch', componentMeta.events.onSearch, currentState, components)}
|
||||||
|
|
||||||
{renderQuerySelector(component, dataQueries, eventOptionUpdated, 'onBulkUpdate', componentMeta.events.onBulkUpdate)}
|
{renderQuerySelector(component, dataQueries, eventOptionUpdated, 'onBulkUpdate', componentMeta.events.onBulkUpdate)}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -174,9 +174,9 @@ export function onEvent(_ref, eventName, options) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (eventName === 'onPageChanged') {
|
if (['onPageChanged', 'onSearch'].includes(eventName)) {
|
||||||
const { component } = options;
|
const { component } = options;
|
||||||
const event = component.definition.events.onPageChanged;
|
const event = component.definition.events[eventName];
|
||||||
|
|
||||||
if (event.actionId) {
|
if (event.actionId) {
|
||||||
executeAction(_self, event);
|
executeAction(_self, event);
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue