Solved

GridMVC

Posted on 2014-01-28
7
748 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
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
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…

920 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

14 Experts available now in Live!

Get 1:1 Help Now