3

So the default behavior for the edit button inside each row of jqGrid is to open the form in the same page, right?

I need it to open another view, another URL.

I've managed to do this with the edit button that is located in the grid-pager, using the .navButtonAdd method. But I can't figure out how to do the same for the row buttons.

Can anyone help me, please?

1 Answers1

1

jqGrid don't provide currently any simple way to replace the call of editing to another method or to include custom button. What you can do alternatively is "subclassing" $.fn.fmatter.rowactions function like I describe it in the answer. The $.fn.fmatter.rowactions function will be called on click on any from action buttons. So you can test whether the act parameter is "edit" or not. In case of non "edit" button you can forward the call to original $.fn.fmatter.rowactions function. In case of "edit" button you can do any your custom action instead.

UPDATED: The exact implementation depends a little from the version of jqGrid which you use because parameters and the value of this of the function $.fn.fmatter.rowactions are different for different versions of jqGrid. I created for you the demo which uses free jqGrid 4.8 (see readme and wiki). I used the following code for subclassing

var orgRowActions = $.fn.fmatter.rowactions;
$.fn.fmatter.rowactions = function (e, act) {
    var $grid = $(this).closest("table.ui-jqgrid-btable"),
        rowid = $(this).closest("tr.jqgrow").attr("id");

    if (act === "edit") {
        $grid.jqGrid("viewGridRow", rowid);
        return false;
    }
    return orgRowActions.call(this, e, act);
}

As the result the "Edit" button starts "View" instead of edit form.

I plan to include more customization possibilities in the next version of free jqGrid. So one will be able to create custom inline icon without the tricks with subclassing.

Community
  • 1
  • 1
Oleg
  • 220,925
  • 34
  • 403
  • 798
  • 1
    Thanks for helping me, Oleg. I think I'm doing something wrong, though. Sorry, this is kinda obscure to me :/ Based on the link you posted, I'm doing this: `var orgRowActions = $.fn.fmatter.rowactions; $.fn.fmatter.rowactions = function (rid, gid, act, pos) { var $grid = $("#" + $.jgrid.jqID(gid)), rowData = $grid.jqGrid("getLocalRow", rid), isNonEditable = false, result; if (act === "edit") { window.location = myURL; } result = orgRowActions.call(this, rid, gid, act, pos); return result; }` Any thoughts on where I'm going wrong? – Lucas Gabriel Mar 26 '15 at 17:30
  • 2
    @LucasGabriel: I created the demo for you which demonstrates the implementation. See **UPDATED** part of my answer. – Oleg Mar 26 '15 at 18:16
  • thank you so much! that was it. I'm using version 4.6.0 and the parameters are different, indeed. it's working just fine now! – Lucas Gabriel Mar 26 '15 at 18:25
  • 1
    @LucasGabriel: You are welcome! I think that the interface of `$.fn.fmatter.rowactions` is the same in 4.6.0 and in free jqGrid 4.8, so you can use the same code in 4.6 too. I still recommend you to try free jqGrid which is free of cause like jqGrid 4.6 and it contains many new features and bug fixes. It's the fork of jqGrid which I will continue to develop in the future. – Oleg Mar 26 '15 at 18:25
  • I'll be using that, then. my project is in early stage so I'd better change it right away. – Lucas Gabriel Mar 26 '15 at 18:43