Solved

GridMVC

Posted on 2014-01-28
7
771 Views
Last Modified: 2014-01-30
Html.Grid(Model).Named("BatchGrid").Columns(columns => 
{
columns.Add(c => c.SC).Titled("C").Filterable(true);
columns.Add(c => c.ItemDescription).Titled("Description");
columns.Add(c => c.Price).Css("ColorRed").Titled("Price Compare");
columns.Add(c => c.CreatedDate).Titled("Created Date").Format("{0:dd-MMM-yyyy}");
}).WithPaging(10).Sortable(true)

Open in new window

I would like to change my price based off value. If  it is a negative price less say color red if not green. Not sure where can I do this in GridMVC. I read the documentation. I think maybe using filter.
0
Comment
Question by:sevensnake77
  • 4
  • 3
7 Comments
 
LVL 23

Accepted Solution

by:
Ioannis Paraskevopoulos earned 500 total points
ID: 39817433
Hi,

I have checked the documentation myself and it doesn't seem to be a native way of doing this.

I would suggest using javascript (jquery).

@Html.Grid(Model).Named("BatchGrid").Columns(columns => 
{
columns.Add(c => c.SC).Titled("C").Filterable(true);
columns.Add(c => c.ItemDescription).Titled("Description");
columns.Add(c => c.Price).Css("PriceTag").Titled("Price Compare");
columns.Add(c => c.CreatedDate).Titled("Created Date").Format("{0:dd-MMM-yyyy}");
}).WithPaging(10).Sortable(true)


<script src="../../Scripts/jquery-1.7.1.min.js" type="text/javascript"></script>
<script src="../../Scripts/jquery-ui-1.8.20.min.js" type="text/javascript"></script>
<script type ="text/javascript" >
    $(".PriceTag").each(function () {
        if ($(this).text() < 0) {
            $(this).addClass("ColorRed")
        }
    });
   
</script>

Open in new window



Giannis
0
 
LVL 23

Expert Comment

by:Ioannis Paraskevopoulos
ID: 39820398
Hi,

As a matter of fact, there is a native way of doing what you need, and i think it is preferable:

@Html.Grid(Model).Named("BatchGrid").Columns(columns => 
{
columns.Add(c => c.SC).Titled("C").Filterable(true);
columns.Add(c => c.ItemDescription).Titled("Description");
columns.Add().Encode(false).Sanitize(false).RenderValueAs(c =>@<span class = "@((c.Price<0)?"ColorRed":"Normal")">@c.Price</span>).Titled("Price Compare");
columns.Add(c => c.CreatedDate).Titled("Created Date").Format("{0:dd-MMM-yyyy}");
}).WithPaging(10).Sortable(true)

Open in new window


Giannis
0
 
LVL 9

Author Comment

by:sevensnake77
ID: 39821365
Encode is  not found in the current context
0
Guide to Performance: Optimization & Monitoring

Nowadays, monitoring is a mixture of tools, systems, and codes—making it a very complex process. And with this complexity, comes variables for failure. Get DZone’s new Guide to Performance to learn how to proactively find these variables and solve them before a disruption occurs.

 
LVL 9

Author Closing Comment

by:sevensnake77
ID: 39821379
worked great thanks
0
 
LVL 23

Expert Comment

by:Ioannis Paraskevopoulos
ID: 39821457
Hi,

Sorry but that was a typo. It is Encoded and not Encode. Give it a try.

Giannis
0
 
LVL 9

Author Comment

by:sevensnake77
ID: 39821902
That worked out also. sorry I closed it before you got back.
0
 
LVL 23

Expert Comment

by:Ioannis Paraskevopoulos
ID: 39821950
No problem... Since both solutions work. I would prefer the second one as it is native, though the first would be a nice workaround.

I also have to say, that i came up to that solution after wondering how i could add an image in a cell.

I also have to thank you to briniging this great library to my attention, as i am kind new in ASP MVC too and still learning.

Giannis
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This article describes relatively difficult and non-obvious issues that are likely to arise when creating COM class in Visual Studio and deploying it by professional MSI-authoring tools. It is assumed that the reader is already familiar with the cla…
In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…

733 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question