Conditional hide cell value or not depending on another value

Sep 9, 2011 at 1:54 PM

"Depending on the value of a status field the user should see an edit button or not in the grid row"

--> this status field is a real property of the model and resides also in the database.

With jqGrid I see no other solution then also set this status field as a column, set it hidden because user must not see this internal status field and write a javascript function to manipulate the grid.

I don't like this, because we send data over the wire not really needed by the user, only for conditional hiding.

Plus I like much more to write c# code then javascript code ;-)

If we could access via lambda expression the item row itself, like in WebGrid from MVC....

For example:

.SetColumns<yourModelClass>(sc =>
            sc.Add(x => x.PropText).SetCellValueHidden(x => x.PropStatus > 10 ? true : false); 
            sc.Add(x => x.PropDate).SetFormatter(x => x.PropDate.Year < 2000 ? "'date'" : "'your own function'"); 
            sc.Add(x => x.Prop1).SetEditable(x => x.PropStatus > 10 ? true : false); 

But is this possible?

I don't think so, the 'frame' of jqGrid is build in the view, resulting in the final html page and is then receiving the data via a json result.
The options of the jqGrid are at that moment already defined. We don't know the values of the fields at the moment the code in the example above is executed.

Of am I thinking wrong?

Sep 9, 2011 at 3:15 PM

You'r basically correct - the view is being built in the view. this is jqGrid and jQuery based controls (and ultimately the entire MVC.Controls library) biggest advantage, but also disadvantage.

One of the thing's I've been working on for the next release is the ability to have conditional row\cell style.
I couldn't find a decent way to implement this directly, so what I'm currently trying to do is to "serialize" this lambda\proprties into an meta-structure that will be sent to the grid (using the grid's userdata property) and will be used by a script that will run after the grid has finished loading and apply the custom styling according to the meta information's values.

Any other possible solutions are welcomed.

Sep 23, 2011 at 6:15 AM

Ok, I saw that "jqgrid userdata thing" amongst the jqgrid options. Maybe this can be a solution.
But what about performance? The client browser (= probably a light system) will do the main work and the server nothing (= heavy system).
Plus the fact that extra data will travel on the wire...
Don't like this idea, but in the concept of jqgrid, there is no other solution, I think

For the moment I must abandon the implementation of jqgrid in our project, because of a strict planning and time that is running away.

Will be back when I have again some time.

Keep up the good work!

Sep 24, 2011 at 4:57 PM

Considering that a standard grid page is pretty small (< 100 rows) performance should'nt be a problem.

Except of the 2 issues already discussed, if there's any speciall features missing you see as mandatory feel free to contact me and I'll try to squees for the next release.