Closed kai-breitbarth-zz closed 8 years ago
You can easily do this with javascript
1) Add a css class to grid rows you want to pre-select
g.column ... do |rec|
if ...
[rec.foo , {class: 'your-preselect-class'}] # will add this class to <tr>
else
rec.foo
end
end
Example: http://wicegrid.herokuapp.com/styling
2) then in JS on dom:loaded:
$('.your-preselect-class .sel input').prop('checked', true)
ugly
This is called web development.
Bloated APIs are ugly.
True. But it would be nicer if auto_column would recognize something like @selected by itself. This way I wouldn't need javascript. I implemented it yesterday and it works. But you need to use row_attributes to get the class at the tr-tag:
g.row_attributes do |c|
if @selected && @selected.include?(c.id.to_s)
{class: 'preselected-row'}
end
end
And a little coffee script
$(document).ready ->
$('.preselected-row .sel input').prop 'checked', true
Maybe it's worth to mention it in your example page. Btw. don't get me wrong, I really like this framework!
That's almost exactly how I suggested it, I think I made a mistake by not choosing row_attributes
, but the idea is the same. I see no problem in this approach. But if you feel like adding such a feature to auto_column I would be willing to accept a pull request
Thanks for this. Works good. However it fails when the grid is refreshed by setting a filter. Did you find a solution for this as well?
Best
How it is possible to mark an action_column as selected? Would be nice if in the controller something like @selected = ["2", "34, "78"] is possible to pre-select rows with the action_column