pivottable
pivottable copied to clipboard
Typescript definition file
Hi Nicolas, I am using the pivot table within a typescript app, and I put together a typescript definition file so I thought I would share it with you in case anyone else could find it useful. I haven't gone as far as branching/creating a pull request, just copy the below into a file called pivottable.d.ts:
// PivotTable Typescript definition file
interface PivotOptions
{
/**
* array of attribute names to use as rows, defaults to []
*/
rows?: string[];
/**
* array of attribute names for use as columns, defaults to []
*/
cols?: string[];
/**
* constructor for an object which will aggregate results per cell, defaults to count()
*/
aggregator?: any;
/**
* function to generate output from pivot data structure (defaults to simple table)
*/
renderer?: any;
/**
* object to define derived attributes, defaults to {}
*/
derivedAttributes?: any;
/**
* function called on each record, returns false if the record is to be excluded from the input before rendering or true otherwise, (defaults to returning true for all records)
*/
filter?: any;
/**
* object passed through to renderer as options
*/
rendererOptions?: any;
/**
* locale-specific strings for error messages
*/
localeStrings?: any;
}
interface PivotUiOptions
{
/**
* dictionary of rendering functions, defaulting with various table renderers
*/
renderers?: any;
/**
* dictionary of generators for aggregation functions in dropdown, defaulting to common aggregators
*/
aggregators?: any;
/**
* array of strings, attribute names to prepopulate in row area, default is []
*/
rows?: string[];
/**
* array of strings, attribute names to prepopulate in cols area, default is []
*/
cols?: string[];
/**
* array of strings, attribute names to prepopulate in vals area, default is []
*/
vals?: string[];
/**
* string, aggregator to prepopulate in dropdown (key to aggregators object), default is first key in aggregators
*/
aggregatorName?: string;
/**
* string, renderer to prepopulate in radio button (key to renderers object), default is first key in renderers
*/
rendererName?: string;
/**
* object, defines derived attributes, default is {}
*/
derivedAttributes?: any;
/**
* function called on each record, returns false if the record is to be excluded from the input before rendering or true otherwise, (defaults to returning true for all records)
*/
filter?: any;
/**
* object, defaults to {}, keys are attribute names and values are arrays of attribute values which denote records to exclude from rendering (used to prepopulate the filter menus that appear on double-click)
*/
exclusions?: any;
/**
* array of strings, defaults to [], contains attribute names to omit from the UI
*/
hiddenAttributes?: string[];
/**
* integer, defaults to 50, maximum number of values to list in the double-click menu
*/
menuLimit?: number;
/**
* object, defaults to null, passed through to renderer as options
*/
rendererOptions?: any;
/**
* function, called upon renderer refresh with an object representing the current UI settings
*/
onRefresh?: (options: PivotUiOptions) => void;
/**
* object, defaults to English strings - locale-specific strings for UI display
*/
localeStrings?: any;
/**
* boolean, defaults to false, controls whether or not unused attributes are kept sorted in the UI
*/
autoSortUnusedAttrs?: boolean;
/**
* boolean, defaults to false, controls whether or not unused attributes are shown vertically instead of the default which is horizontally
*/
unusedAttrsVertical?: boolean;
}
interface JQuery
{
/**
* Renders pivot table
* @param data Data to use for pivot
* @param options Pivot options
*/
pivot(data: any[], options?: PivotOptions): JQuery
/**
* Renders interactive pivot table
* @param data Data to use for pivot
* @param options PivotUI options
* @param overwrite Whether to overwrite state with supplied options when calling pivotUI repeatedly
* @param locale String defaulting to 'en' which controls the default locale
*/
pivotUI(data: any[], options?: PivotUiOptions, overwrite?:boolean, locale?:string): JQuery
}
// require js module support
declare var PivotTable: any;
declare module "pivottable" {
export = PivotTable;
}
Very cool, thank you!
Any reason why this has not been added yet @nicolaskruchten ?
Does it need additional work?
@SamMousa I'm not able to commit the time to test and maintain this file, so I'm leery of merging it to master.
Can someone help me to implement in this my project?
I will be happy to pilot this if you can provide me a repo pivot table is a hot item be nice if it were remodeled in pure typescript
@nhhockeyplayer I think the common practice here is to contribute a third-party type definition to https://github.com/DefinitelyTyped/DefinitelyTyped
thanks for saving me the time to type this up!
Hi, can anyone provide a code snippet as to how to generate a pivottable using the custom definition file? I am not sure why my compiler is not detecting my newly created type :/