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 (
<> <>
{!!reload && (
<DropDownMenuItem onClick={reload} keyText="F5"> <DropDownMenuItem onClick={reload} keyText="F5">
Reload Reload
</DropDownMenuItem> </DropDownMenuItem>
<DropDownMenuDivider /> )}
{!!reload && <DropDownMenuDivider />}
<DropDownMenuItem onClick={copy} keyText="Ctrl+C"> <DropDownMenuItem onClick={copy} keyText="Ctrl+C">
Copy Copy
</DropDownMenuItem> </DropDownMenuItem>
{revertRowChanges && (
<DropDownMenuItem onClick={revertRowChanges} keyText="Ctrl+R"> <DropDownMenuItem onClick={revertRowChanges} keyText="Ctrl+R">
Revert row changes Revert row changes
</DropDownMenuItem> </DropDownMenuItem>
)}
{deleteSelectedRows && (
<DropDownMenuItem onClick={deleteSelectedRows} keyText="Ctrl+Delete"> <DropDownMenuItem onClick={deleteSelectedRows} keyText="Ctrl+Delete">
Delete selected rows Delete selected rows
</DropDownMenuItem> </DropDownMenuItem>
)}
{insertNewRow && (
<DropDownMenuItem onClick={insertNewRow} keyText="Insert"> <DropDownMenuItem onClick={insertNewRow} keyText="Insert">
Insert new row Insert new row
</DropDownMenuItem> </DropDownMenuItem>
)}
<DropDownMenuDivider /> <DropDownMenuDivider />
{setNull && (
<DropDownMenuItem onClick={setNull} keyText="Ctrl+0"> <DropDownMenuItem onClick={setNull} keyText="Ctrl+0">
Set NULL Set NULL
</DropDownMenuItem> </DropDownMenuItem>
)}
{exportGrid && <DropDownMenuItem onClick={exportGrid}>Export</DropDownMenuItem>} {exportGrid && <DropDownMenuItem onClick={exportGrid}>Export</DropDownMenuItem>}
{filterSelectedValue && (
<DropDownMenuItem onClick={filterSelectedValue} keyText="Ctrl+F"> <DropDownMenuItem onClick={filterSelectedValue} keyText="Ctrl+F">
Filter selected value Filter selected value
</DropDownMenuItem> </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}
/> />