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
reesercollins and cccs-Dustin authored Jul 25, 2022
1 parent efd8969 commit f0ff141
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 @@ -565,6 +565,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 @@ -17,6 +17,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 f0ff141

Please sign in to comment.