Skip to content

EdsDataGrid column config default values #3708

Open
@adnejacobsen

Description

Is your feature request related to a problem? Please describe.

If cell.getValue() can not find a value in the row using the specified accessorKey it prints a warning for each part of the key that returns undefined. We're using EdsDataGrid on a dataset where there is no guarantee that every column exists in every row. The console fills up with, what is in our case, unnecessary warnings.

Describe the solution you'd like

It would be nice if we could specify default/fallback values in the column config that will be displayed if the accessorKey returns undefined on the current row. Or a bool flag, i.e lignoreUndefined: true to prevent warnings. Example:

{
	accessorKey: "_source.fmu.iteration.name",
	header: "Iteration",
	id: "iter",
	size: 80,
	defaultValue: "-"
},

Describe alternatives you've considered

We have been using column configs like this:

{
	accessorKey: "_source.fmu.iteration.name",
	header: "Iteration",
	id: "iter",
	size: 80,
	cell: ({ cell }) => cell.getValue() || "-",
},

It will display - for values that does not exist, letting us differentiate between non-existing properties and empty properties.

To prevent the warnings we have made the following workaround:

// wrapper function
const getCellValue = (cell, fallback = null) => {
        let accessor = cell.column.columnDef.accessorKey.split(".");
	let value = cell.row.original;

	for (let key of accessor) {
		if (value?.[key]) {
			value = value[key];
		} else {
			return fallback;
		}
	}

	return value;
};

// column config
{
	accessorKey: "_source.fmu.iteration.name",
	header: "Iteration",
	id: "iter",
	size: 80,
	cell: ({ cell }) => getCellValue(cell, "-"),
},

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions