Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EdsDataGrid column config default values #3708

Open
adnejacobsen opened this issue Dec 17, 2024 · 0 comments
Open

EdsDataGrid column config default values #3708

adnejacobsen opened this issue Dec 17, 2024 · 0 comments

Comments

@adnejacobsen
Copy link

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, "-"),
},
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant