programcsharp / griddly

Hybrid grid -- Razor/MVC AJAX/HTML5
http://griddly.com
MIT License
16 stars 10 forks source link

Select column input "value" is not always the id value set #69

Open ithielnor opened 8 years ago

ithielnor commented 8 years ago

If you write your settings like:

var grid = new GriddlySettings<Drg.M3.Domain.Events.Registration>();
grid.RowId(x => x.Blah.Id);
grid.SelectColumn(x => x.Id);

The input in the select column will be rendered with x.Blah.Id as the value instead of x.Id. However, if you write

var grid = new GriddlySettings<Drg.M3.Domain.Events.Registration>();
grid.SelectColumn(x => x.Id);
grid.RowId(x => x.Blah.Id);

The input value will be x.Id as expected. It seems to me that the value should always be whatever expression was specified in SelectColumn

programcsharp commented 8 years ago

It looks like this is by design: https://github.com/programcsharp/griddly/commit/dc935e941a636be876c6a066b7f0ad78576e7c0a#diff-afcf37e41443e6efc6072140d2dd621fR24

SelectColumn adds one (or more) RowId's to the settings, same as RowId. It then picks the first RowId to use as value but adds all of them as data attributes. Normally this works fine, but if you RowId first then that id will be first in the RowId's dictionary instead.

Maybe we need to rework the RowId design a bit? #26 is still open to allow setting names for buttons easier.

ithielnor commented 8 years ago

I know that's how the render works, but the helper function .SelectColumn should be changed I think.

It seems to me that if you specify an Id in the .SelectColumn it should always win, no matter where you put other RowIds in the configuration.

Why not make .SelectColumn to an Insert(0, func) so value will always be the id specified in the helper column. Though, this does get funky with multiple select columns...