Typescript: button().popover() missing definitions
Typescript: button().popover() missing definitions
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
contentisfalse, but the docs don't mention it. Is that public API? optionsis 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
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
popoverOptionsparameter for SearchPanes, per your suggestion (with a slight name change). It isanyin 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
fixedfor 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 forcolumns, 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