datagrid context menu

This commit is contained in:
Jan Prochazka 2020-11-19 12:42:13 +01:00
parent 682f53881d
commit 9a2520a10a
5 changed files with 40 additions and 25 deletions

View File

@ -58,6 +58,7 @@ export abstract class GridDisplay {
filterable = false; filterable = false;
editable = false; editable = false;
isLoadedCorrectly = true; isLoadedCorrectly = true;
supportsReload = false;
setColumnVisibility(uniquePath: string[], isVisible: boolean) { setColumnVisibility(uniquePath: string[], isVisible: boolean) {
const uniqueName = uniquePath.join('.'); const uniqueName = uniquePath.join('.');

View File

@ -32,6 +32,7 @@ export class TableGridDisplay extends GridDisplay {
this.filterable = true; this.filterable = true;
this.sortable = true; this.sortable = true;
this.editable = true; this.editable = true;
this.supportsReload = true;
this.baseTable = this.table; this.baseTable = this.table;
if (this.table && this.table.columns) { if (this.table && this.table.columns) {
this.changeSetKeyFields = this.table.primaryKey this.changeSetKeyFields = this.table.primaryKey

View File

@ -17,6 +17,7 @@ export class ViewGridDisplay extends GridDisplay {
this.filterable = true; this.filterable = true;
this.sortable = true; this.sortable = true;
this.editable = false; this.editable = false;
this.supportsReload = true;
} }
getDisplayColumns(view: ViewInfo) { getDisplayColumns(view: ViewInfo) {

View File

@ -15,30 +15,42 @@ export default function DataGridContextMenu({
}) { }) {
return ( return (
<> <>
<DropDownMenuItem onClick={reload} keyText="F5"> {!!reload && (
Reload <DropDownMenuItem onClick={reload} keyText="F5">
</DropDownMenuItem> Reload
<DropDownMenuDivider /> </DropDownMenuItem>
)}
{!!reload && <DropDownMenuDivider />}
<DropDownMenuItem onClick={copy} keyText="Ctrl+C"> <DropDownMenuItem onClick={copy} keyText="Ctrl+C">
Copy Copy
</DropDownMenuItem> </DropDownMenuItem>
<DropDownMenuItem onClick={revertRowChanges} keyText="Ctrl+R"> {revertRowChanges && (
Revert row changes <DropDownMenuItem onClick={revertRowChanges} keyText="Ctrl+R">
</DropDownMenuItem> Revert row changes
<DropDownMenuItem onClick={deleteSelectedRows} keyText="Ctrl+Delete"> </DropDownMenuItem>
Delete selected rows )}
</DropDownMenuItem> {deleteSelectedRows && (
<DropDownMenuItem onClick={insertNewRow} keyText="Insert"> <DropDownMenuItem onClick={deleteSelectedRows} keyText="Ctrl+Delete">
Insert new row Delete selected rows
</DropDownMenuItem> </DropDownMenuItem>
)}
{insertNewRow && (
<DropDownMenuItem onClick={insertNewRow} keyText="Insert">
Insert new row
</DropDownMenuItem>
)}
<DropDownMenuDivider /> <DropDownMenuDivider />
<DropDownMenuItem onClick={setNull} keyText="Ctrl+0"> {setNull && (
Set NULL <DropDownMenuItem onClick={setNull} keyText="Ctrl+0">
</DropDownMenuItem> Set NULL
</DropDownMenuItem>
)}
{exportGrid && <DropDownMenuItem onClick={exportGrid}>Export</DropDownMenuItem>} {exportGrid && <DropDownMenuItem onClick={exportGrid}>Export</DropDownMenuItem>}
<DropDownMenuItem onClick={filterSelectedValue} keyText="Ctrl+F"> {filterSelectedValue && (
Filter selected value <DropDownMenuItem onClick={filterSelectedValue} keyText="Ctrl+F">
</DropDownMenuItem> Filter selected value
</DropDownMenuItem>
)}
{openQuery && <DropDownMenuItem onClick={openQuery}>Open query</DropDownMenuItem>} {openQuery && <DropDownMenuItem onClick={openQuery}>Open query</DropDownMenuItem>}
<DropDownMenuItem onClick={openFreeTable}>Open selection in free table editor</DropDownMenuItem> <DropDownMenuItem onClick={openFreeTable}>Open selection in free table editor</DropDownMenuItem>
</> </>

View File

@ -345,13 +345,13 @@ export default function DataGridCore(props) {
event.pageY, event.pageY,
<DataGridContextMenu <DataGridContextMenu
copy={handleCopy} copy={handleCopy}
revertRowChanges={revertRowChanges} revertRowChanges={grider.containsChanges ? revertRowChanges : null}
deleteSelectedRows={deleteSelectedRows} deleteSelectedRows={grider.editable ? deleteSelectedRows : null}
insertNewRow={insertNewRow} insertNewRow={grider.editable ? insertNewRow : null}
reload={() => display.reload()} reload={display.supportsReload ? () => display.reload() : null}
setNull={setNull} setNull={grider.editable ? setNull : null}
exportGrid={exportGrid} exportGrid={exportGrid}
filterSelectedValue={filterSelectedValue} filterSelectedValue={display.filterable ? filterSelectedValue : null}
openQuery={openQuery} openQuery={openQuery}
openFreeTable={handleOpenFreeTable} openFreeTable={handleOpenFreeTable}
/> />