[eluser]Unknown[/eluser]
Hey all, I just started playing with flexigrid, and I too, wanted single-select and a couple other things so I implemented them. Below is the code I used to implement :
* single select - only one row is selected at a time
* multiple rows can be selected using the ctrl key. Still trying to figure out how to remove the ugly borders that show up with the Ctrl key.
* two new events onRowSelected and onRowDeselect. The 2nd one is fired when you de-select a selected row.
I want to thank Paulo for an excellent piece of code in Flexigrid.
I also want to thank SeanRock for starting me off on this modification.
Now for the code :
on line 52 where you see :
Code:
onSubmit: false // using a custom populate function
add a comma after false and add :
Code:
onRowSelected: false, // event to fire when row selected
onRowDeselect: false, //event to fire when row has been deselected
multiSelect: false // can select multiple rows without a modifier key
Then down to line 708, where you see :
Code:
.click(
function (e)
{
var obj = (e.target || e.srcElement); if (obj.href || obj.type) return true;
$(this).toggleClass('trSelected');
}
)
and replace that function call with :
Code:
.click(
function (e)
{
var obj = (e.target || e.srcElement); if (obj.href || obj.type) return true; //enable default behaviour for links and form elements
$(this).toggleClass('trSelected'); // flip the switch
var selId = this.id.substring(3);
if ( $(this).hasClass('trSelected') ) {
// ToDo: Add functionality to implement shift button
if (!( p.multiSelect || e.ctrlKey )) {
$('tbody tr.trSelected').not(this).removeClass('trSelected'); // only one row should be selected.
}
if (p.onRowSelected) p.onRowSelected(selId, $(this), $(g));
} else { // switch was on, just turned it off
if ( p.onRowDeselect ) p.onRowDeselect(selId, $(this),$(g)); // fire the onRowDeselcted event
// p.onRowSelected(selId,$(this),$(this).parent().parent().parent());
return ;
}
}
)
I hope this helps someone.
Also, where is the proper place to submit patches and feature requests for flexigrid? Hey Paulo, I want to help. Let's get this thing better organized and documented.