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

Doctrine and filter numeric column #1059

Open
krajcikondra opened this issue Dec 30, 2022 · 1 comment
Open

Doctrine and filter numeric column #1059

krajcikondra opened this issue Dec 30, 2022 · 1 comment

Comments

@krajcikondra
Copy link

Hi,

I have project with contribute/nettrine and contributte/datagrid. I have numeric column "year".

		$grid->addColumnNumber('year', 'Year');
		$grid->addFilterText('year', 'Year');

When I write some value to filter input and press enter I get following error:

An exception occurred while executing a query: SQLSTATE[42883]: Undefined function: 7 ERROR: function lower(integer) does not exist
LINE 1: ...ECT COUNT(b0_.id) AS sclr_0 FROM "book" b0_ WHERE LOWER(b0_....
^
HINT: No function matches the given name and argument types. You might need to add explicit type casts

Is it bug or do I something bad?

Thanks in advance

@juniwalk
Copy link
Contributor

Hi, you have to use custom condition for the filter and write custom DQL to handle this.

$grid->addFilterText('number', 'web.order.number')->setCondition(function($qb, $query) {
	$qb->andWhere('cast(e.number as varchar) LIKE :number');
	$qb->setParameter('number', '%'.$query.'%');
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants