Solved

GridMVC

Posted on 2014-01-28
7
736 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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

What my article will show is if you ever had to do processing to a listbox without being able to just select all the items in it. My software Visual Studio 2008 crystal report v11 My issue was I wanted to add crystal report to a form and show…
Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
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…

706 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now