Search code examples
javascriptjquerystruts2jqgridstruts2-jquery

Override default navigation buttons functionality in jqGrid


Question is simple: Is there a way to override the behaviour of the default buttons placed in the navigation bar of a jqGrid grid?

I'm using the struts2 plugin and I needed to launch an action if user clicks the add button or the edit button to redirect to another page in which this things are done. I wondered if it was possible to override it's default behaviour as I think it's cleaner than defining myself new "add" and "edit" buttons.

Documentation for adding such new buttons HERE.


Solution

  • You create first navigator bar using navigator="true", but with navigatorAdd="false", navigatorEdit="false", navigatorDelete="false" and so on (see the documentation). In the way you will have navigator bar without any buttons. Then you add custom buttons with the same icons like standard editing buttons (see the example which you referenced). You need uses icon: 'ui-icon-pencil' for Edit, ui-icon-plus for Add, and ui-icon-trash for delete. Inside of onclick callback you can place any your custom JavaScript code.

    UPDATED: The names and the values of navigatorExtraButtons are build based on the options of navButtonAdd method. I've found additionally this code which should help you.