MvcContrib.Grid Visible method - strange behaviour

173 views
Skip to first unread message

cpat

unread,
Aug 24, 2011, 6:38:08 AM8/24/11
to mvccontrib-discuss
I'm using the MvcContrib Grid and I'd like to set the Visible property
of columns depending on whether the corresponding col Id is present in
a list of selected Col Id. In my View, I have the following function
created

@functions {

public bool testFn(int colId, String[] str)
{
String temp = colId.ToString();
if (Array.Exists(str, s => s.Equals(temp))) {
return true;
} else {
return false;
}
}
}
and a str array also defined as follows

@{
var myStrArr = ViewBag.selCols as String[];
}

I'm calling the function from the Visible method of the Grid as
follows

Visible(testFn(0, myStrArr))

The method however seems to completely ignore the value being
returned. If I change my function to be simple as

public bool testFn(int colId, String[] str)
{
String temp = colId.ToString();
if (1 == 2) {
return true;
} else {
return false;
}
}
and then call it exactly the same way from the Visible method, it
seems to understand the false value being returned.

Can anybody help me resolve this please? I'm not sure what I am doing
wrong. Stepping into the code shows me that the return value is
correctly set to true or false depending on the inputs and the Visible
property is also set to False, but this is totally being ignored when
the table is rendered.

Thanks

Jeremy Skinner

unread,
Aug 25, 2011, 6:55:05 AM8/25/11
to mvccontri...@googlegroups.com
Hi

I'm not able to reproduce this - I tried running your code and it worked correctly. The column was hidden provided that the value for colId was present in the string array. If you're still having problems then feel free to put together a complete working sample project that reproduces the problem and then email it to me, and I'll investigate further.

Jeremy


--
Contact Jeffrey Palermo or Eric Hexter with specific questions about the MvcContrib project.  Or go to http://mvccontrib.org

To unsubscribe from this group, send email to mvccontrib-disc...@googlegroups.com
For more options, visit this group at http://groups.google.com/group/mvccontrib-discuss?hl=en

cpat

unread,
Aug 25, 2011, 9:24:45 AM8/25/11
to mvccontrib-discuss
Hi Jeremy,
Thank you for looking into this issue.

I would be interested to know if you are calling other methods
along with the Visible method on the Grid columns. Right now, a
sample of my grid looks like this:

@Html.Grid(Model).Sort(ViewBag.sort as GridSortOptions).Columns(column
=> {
column.For(issue => Html.CheckBox("IssueSelected", false, new
{ id = "IssueSelected",
value=issue.ID})).Named("Select").SortColumnName("
").Visible(testFn((int)IssueEnum.ID, selCol));
column.For(issue => Html.ActionLink(" ", "Edit", new { id =
issue.ID, areas = "Issues", controller = "Main"}, new
{ @id="editBtn"})).Named("Edit").SortColumnName(" ");
column.For(issue => Html.ActionLink(issue.ID.ToString(), "Edit",
new { id = issue.ID, areas = "Issues", controller =
"Main" })).Named("ID").Sortable(true).Visible(testFn("9", selCol));
column.For(issue =>
issue.issueSummary).Named("Summary").Sortable(true);

I'm going to try and make it just the barebones of the column
definitions and see if that is the issue. If you don't mind, would
you copy your grid code please?

Thank you,




On Aug 25, 2:55 pm, Jeremy Skinner <jer...@jeremyskinner.co.uk> wrote:
> Hi
>
> I'm not able to reproduce this - I tried running your code and it worked
> correctly. The column was hidden provided that the value for colId was
> present in the string array. If you're still having problems then feel free
> to put together a complete working sample project that reproduces the
> problem and then email it to me, and I'll investigate further.
>
> Jeremy
>
> > MvcContrib project.  Or go tohttp://mvccontrib.org
>
> > To unsubscribe from this group, send email to
> > mvccontrib-disc...@googlegroups.com
> > For more options, visit this group at
> >http://groups.google.com/group/mvccontrib-discuss?hl=en- Hide quoted text -
>
> - Show quoted text -

cpat

unread,
Aug 25, 2011, 10:43:51 AM8/25/11
to mvccontrib-discuss
Hi Jeremy,
Been testing some more. And finally figured out that it is a
problem with the View not being rendered again correctly through the
Ajax call! So not a problem with the grid code at all, just something
silly I am doing. Thank you for looking into this.

Ta,
Chandini
> > >http://groups.google.com/group/mvccontrib-discuss?hl=en-Hide quoted text -
>
> > - Show quoted text -- Hide quoted text -
Reply all
Reply to author
Forward
0 new messages