views:

94

answers:

1

Hello,

I am using custom edit/delete functions in jqGrid and I really enjoyed the fact that they call your custom function after checking if a row was selected or not.

Now I would like to add two more buttons and I would like to use the same behaviour of the edit/delete, so when a row is selected my function get called but if no rows have been selected they show the default popup that says "please select a row first".

Is there a way to achieve this? Alternatively, is there a way to call the method that is called by the grid itself?

thanks!

+2  A: 

You should test whether any row is selected or not inside the onClickButton method of your custom button (see Jqgrid: navigation based on the selected row as an example). If you want to display exactly the same warning you should follow the code from Preventing the opening of a form on a add button click.

To make all easier I modified an old example for you. On the example you can click on the custom button "My special Action" and see the warning if no row is selected. If some row is selected you can do something with the data from the selected row. Instead of some complex actions I displayed a message only.

UPDATED: The answer to the questions "Adding jqGrid Custom Navigation to Top Toolbar" can be also interesting for you.

Oleg
@Oleg: thanks very much Oleg. It works! Another question: how to add the button to the top toolbar as you've answered to me in this question? `http://stackoverflow.com/questions/3902611/toolbar-in-jqgrid`
Lorenzo
@Lorenzo: You welcome! For moving any elements from one place to another you can use `jQuery.insertAfter` or `jQuery.insertBefore`. See http://stackoverflow.com/questions/2678904/adding-button-to-jqgrid-top-toolbar/2679672#2679672 for details.
Oleg