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 <96579982+cccs-Dustin@users.noreply.github.com>

Co-authored-by: cccs-Dustin <96579982+cccs-Dustin@users.noreply.github.com>
  • Loading branch information
reesercollins and cccs-Dustin committed Jul 25, 2022
1 parent c7189d6 commit 7c85228
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 7c85228

Please sign in to comment.