Solved

GridMVC

Posted on 2014-01-28
7
759 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
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 
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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
A theme is a collection of property settings that allow you to define the look of pages and controls, and then apply the look consistently across pages in an application. Themes can be made up of a set of elements: skins, style sheets, images, and o…
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…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

856 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