Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

open simplified dropdown using new grid #42

Open
vegarringdal opened this issue Dec 30, 2022 · 0 comments
Open

open simplified dropdown using new grid #42

vegarringdal opened this issue Dec 30, 2022 · 0 comments
Labels
documentation Improvements or additions to documentation

Comments

@vegarringdal
Copy link
Owner

vegarringdal commented Dec 30, 2022

let pop: HTMLElement | null = null;

const gridInterfaceEvents = {
    handleEvent: (e: any) => {
        console.log(e);
        if (pop) {
            pop.parentElement?.removeChild(pop);
            pop = null;
        }
        if (e.type === 'cell-focus-button-click' && e.data?.attribute === 'date1') {
            const cell = e.data.cell as HTMLCellElement;
            const rect = cell.getBoundingClientRect();
            const element = document.createElement('simple-html-grid') as GridElement;
            const height = 300;
            const width = 500;
            let top = rect.bottom;
            let left = rect.left;
            if (window.innerHeight < rect.bottom + height) {
                top = rect.top - height - 3;
            }
            if (window.innerWidth < rect.right + width) {
                left = window.innerWidth - width - 3;
            }

            element.style.width = width + 'px';
            element.style.height = height + 'px';
            element.style.display = 'absolute';
            element.style.top = top + 'px';
            element.style.left = left + 'px';
            element.style.boxShadow = '16px 17px 8px 0px rgb(0 0 0 / 20%), 0 6px 20px 0 rgb(0 0 0 / 19%)';

            const gridConfig: GridConfig = {
                panelHeight: 0,
                selectSizeHeight: 1,
                hideLabels: false,
                hideFilter: false,
                footerHeight: 10,
                columnsCenter: [{ width: width, rows: ['WOW'] }],
                attributes: [
                    {
                        attribute: 'WOW',
                        label: 'select cable'
                    }
                ]
            };
            const datasource = new Datasource();

            for (let i = 0; i < 1000; i++) {
                datasource.setData([{ WOW: 'wow' + i }], true);
            }

            const gridInterface = new GridInterface(gridConfig, datasource);
            element.classList.add('simple-html-grid');
            element.connectInterface(gridInterface);
            document.body.appendChild(element);
            pop = element;

            // set focus to first filter
            (element.getElementsByTagName('INPUT')[0] as HTMLInputElement)?.focus();

            element.onclick = (x) => {
                if ((x.target as HTMLElement)?.classList.contains('simple-html-grid-cell-input')) {
                    console.log(datasource.currentEntity);
                    pop.parentElement?.removeChild(pop);
                    pop = null;
                    e.data.target?.focus();
                }
            };

            element.onkeydown = (x) => {
                if (x.code === 'Enter' && (x.target as HTMLElement)?.classList.contains('simple-html-grid-cell-input')) {
                    console.log(datasource.currentEntity);
                    pop.parentElement?.removeChild(pop);
                    pop = null;
                    e.data.target?.focus();
                }
            };
        }

        return true; // to keep subscribing
    }
};
@vegarringdal vegarringdal added the documentation Improvements or additions to documentation label Dec 30, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

No branches or pull requests

1 participant