Skip to content

Commit

Permalink
Add row number option to CCCS-Grid (#181)
Browse files Browse the repository at this point in the history
* Add row number option to CCCS-Grid

* Have row numbers show by default

Co-authored-by: cccs-Dustin <[email protected]>

Co-authored-by: cccs-Dustin <[email protected]>
  • Loading branch information
2 people authored and cccs-RyanS committed Aug 16, 2022
1 parent ad75d2b commit bedea01
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -560,6 +560,18 @@ config.controlPanelSections.push({
},
},
],
[
{
name: 'enable_row_numbers',
config: {
type: 'CheckboxControl',
label: t('Row numbers'),
renderTrigger: true,
default: true,
description: t('Whether to enable row numbers'),
},
},
],
[
{
name: 'page_length',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ export default function transformProps(chartProps: CccsGridChartProps) {
include_search,
enable_grouping,
column_state,
enable_row_numbers,
}: CccsGridQueryFormData = { ...DEFAULT_FORM_DATA, ...formData };
const data = queriesData[0].data as TimeseriesDataRecord[];
const agGridLicenseKey = queriesData[0].agGridLicenseKey as String;
Expand Down Expand Up @@ -167,7 +168,7 @@ export default function transformProps(chartProps: CccsGridChartProps) {
COUNTRY: 'countryValueRenderer',
JSON: 'jsonValueRenderer',
};

const percentMetricValueFormatter = function (params: ValueFormatterParams) {
return getNumberFormatter(NumberFormats.PERCENT_3_POINT).format(
params.value,
Expand Down Expand Up @@ -271,6 +272,16 @@ export default function transformProps(chartProps: CccsGridChartProps) {
}
}

if (enable_row_numbers) {
columnDefs.splice(0, 0, {
headerName: '#',
colId: 'rowNum',
pinned: 'left',
valueGetter: (params: any) =>
params.node ? params.node.rowIndex + 1 : null,
} as any);
}

return {
formData,
setDataMask,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export type CccsGridQueryFormData = QueryFormData & {
page_length: number;
enable_grouping: boolean;
column_state: ColumnState[];
enable_row_numbers: boolean;
};

export interface CccsGridStylesProps {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ describe('CccsGrid buildQuery', () => {
enable_grouping: false,
viz_type: 'my_chart',
column_state: [],
enable_row_numbers: false,
};

it('should build groupby with series in form data', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ describe('CccsGrid tranformProps', () => {
enable_grouping: false,
viz_type: 'my_chart',
column_state: [],
enable_row_numbers: false,
};
const chartProps = new CccsGridChartProps({
formData,
Expand Down

0 comments on commit bedea01

Please sign in to comment.