contributte / datagrid

:muscle: DataGrid for Nette Framework: filtering, sorting, pagination, tree view, table view, translator, etc
https://contributte.org/packages/contributte/datagrid/
MIT License
285 stars 189 forks source link

`ColumnStatus` not working for some reason #1046

Open matronator opened 1 year ago

matronator commented 1 year ago

I have a grid where I need to show two status columns. One is from a varchar/string column (this one works) and the other one is from a bool/tinyint column with numeric index keys and the second one for some reason just won't work. When looking at the generated HTML, it seems to have everything EXCEPT for the button to toggle the dropdown.

This is the code:

$grid->addColumnStatus('enabled', 'Status')
->setCaret(true)
->addOption(1, 'Enabled')
    ->setIcon('check')
    ->setClass('btn-success')
    ->endOption()
->addOption(0, 'Disabled')
    ->setIcon('close')
    ->setClass('btn-danger')
    ->endOption()
->onChange[] = [$this, 'setStatus'];

$grid->addColumnStatus('value', 'Value')
->setOptions(array_map(function($item) {
    return ucfirst($item);
}, MY_CLASS::VALUES))
->onChange[] = [$this, 'setValue'];

And this is the result:

Snímek obrazovky 2022-09-16 v 17 59 08

I tried setting the options with an array instead like in the second one, but it didn't change anything. Why is it not working? Is it maybe the numeric index keys that are causing it?

ikeblaster commented 10 months ago

It's caused by strict comparison in ColumnStatus::getCurrentOption. In your case you should be able to modify your code to addOption(true, 'Enabled') etc. and it should work.