0

In a jqgrid, i have columns that are editable only if a certain column has a given value, is it possible to show / hide those columns on the add / edit form based on that column (select) value ?

I've already been through the aftershowform function, is there any other way to do it ? using aftershowform all fields are shown at first and then made hidden with an ugly render effect.

MaK
  • 596
  • 4
  • 23

1 Answers1

2

You can hide/show any editable column inside of beforeShowForm or afterShowForm callback. It's important to understand that jqGrid fill the form with all editable columns. The form contains rows. Every row have id which build based on the name of editable column. The row id have "tr_" prefix which are appended to the column name (the value of name property in colModel). So if you need to hide the column having name: "Name" then you can do

beforeShowForm: function ($form) { $form.find("#tr_Name").hide(); }

or just

beforeShowForm: function () { $("#tr_Name").hide(); }

(see the answer).

To get rowid which will be currently editing you can use

var rowid = $form.find("#id_g").val();

or

var rowid = $("#id_g").val();

(see the answer). The strange id value "id_g" is the id of hidden element which will be placed by jqGrid in every editing form. Alternatively you can use

var rowid = $(this).jqGrid("getGridParam", "selrow");

because the value from selrow also contains the rowid of the current editing row.

To test content of another column before hiding/showing the row you can use getCell. In case of datatype: "local" (or in case of usage loadonce: true) you can get object with full row data using getLocalRow method.

Community
  • 1
  • 1
Oleg
  • 220,925
  • 34
  • 403
  • 798