Solved

GridMVC

Posted on 2014-01-28
7
787 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:Seven price
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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:Seven price
ID: 39821365
Encode is  not found in the current context
0
Raise the IQ of Your IT Alerts

From IT major incidents to manufacturing line slowdowns, every business process generates insights that need to reach the people required to take action. You need a platform that integrates with your business tools to create fully enabled DevOps toolchains.

You need xMatters.

 
LVL 9

Author Closing Comment

by:Seven price
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:Seven price
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

MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

Question has a verified solution.

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

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…
Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
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…
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …

718 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