≡

Typescript: button().popover() missing definitions

Typescript: button().popover() missing definitions

peter.brunspeter.bruns Posts: 13Questions: 9Answers: 0

Link to test case: https://stackblitz.com/edit/vitejs-vite-j5ptxvfa?file=src%2Fmain.ts&terminal=dev

Error messages shown:

error TS2339: Property 'popover' does not exist on type 'ApiButtonMethods<any>'.

Description of problem:

Hi,

with datatables.net-dt 3.1.5 and datatables.net-buttons-dt 4.1.3, the documented API method button().popover() works at runtime, but it's missing from the TypeScript definitions:

table.button(0).popover('<p>Popover content</p>'); // TS2339
table.button(0).popover(false); // TS2339

My workaround for now:

import type { Api, Dom } from 'datatables.net';
import type { PopoverOptions } from 'datatables.net-buttons-dt';

declare module 'datatables.net' {
    interface ApiButtonMethods<T> {
        popover(content: HTMLElement | Dom<HTMLElement> | string | false, options?: Partial<PopoverOptions>): Api<T>;
    }
}

Some small inconsistencies I noticed:

  • The implementation closes the popover when content is false, but the docs don't mention it. Is that public API?
  • options is documented as "not optional", but it works without it.

Suggestion for SearchPanes: the searchPanes button hardcodes its popover options ({ align: 'container', span: 'container' }), so there's no way to use, for example, collectionLayout: 'fixed'. I needed that because the table sits in a container that clips the popover. My workaround is a custom action that copies the SearchPanes action with different options. It would be great if the button accepted popover options from its config, for example:

{
    extend: 'searchPanes',
    popover: { collectionLayout: 'fixed' },
}

Thanks!

Replies

  • allanallan Posts: 66,186Questions: 1Answers: 11,040 Site admin

    Many thanks for the details here! I've made this commit to Buttons to address the TypeScript and doc errors you mention.

    I've also just committed a new popoverOptions parameter for SearchPanes, per your suggestion (with a slight name change). It is any in TypeScript at the moment as I don't (yet) have a good way to share types between extensions (since Buttons isn't a strict dependency of SearchPanes).

    Using fixed for the collection layout needs a fix in Buttons which I've also just committed, and you'll likely need a little bit of extra CSS to get the alignment correct. There isn't currently a class for fixed to be a wide modal - it does that for columns, but that isn't want is wanted here. I might need to look at adding a new class for it, but at the moment an extra CSS rule will do it.

    Allan

Sign In or Register to comment.