We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy.
Unfortunately, activation email could not send to your email. Please try again.

MVC 3 : Conditional Formating not working

Thread ID:

Created:

Updated:

Platform:

Replies:

101899 Dec 1,2011 01:31 AM Dec 2,2011 01:35 AM ASP.NET MVC (Classic) 3
loading
Tags: Grid
Administrator [Syncfusion]
Asked On December 1, 2011 01:31 AM

Hello Experts,

When we have added ConditionFormat on view side (not from controller). In this, when page loaded first time at that time grid is display based on the condition but when we are doing paging at that time grid is not displaying based on the condition.

Code :
var dictionary = new Dictionary();
dictionary.Add("style", "background-color:#E29100");


.ConditionalFormats(condition =>
{
condition.Add(new GridConditionalFormatDescriptor
{
Name = "TfsTransfer",
Conditions = new System.Collections.ObjectModel.Collection>
{
new GridDataCondition(c => c.TransferredToTfs) { ConditionType = GridDataConditionType.Equals, Value = "Yes" }
},
Cell = new GridCellFormatter { HtmlAttributes = dictionary }
});
})



Thanks
Alok Shah



Eswari S [Syncfusion]
Replied On December 1, 2011 07:13 AM

Hi Alok,

Thank you for using Syncfusion products.

Query #1: when we are doing paging at that time grid is not displaying based on the condition.

If you are using a paging/sorting action, rebind the ConditionalFormats property again to Grid in the post action

[AcceptVerbs(HttpVerbs.Post)]

public ActionResult Index(PagingParams args)
{
IEnumerable data = new NorthwindDataContext().Orders.ToList();
ActionResult result = data.GridActions();

// rebind the action again

var engine = result as GridHtmlActionResult;
engine.GridModel.ConditionalFormats = this.ConditionFormats;
return engine;
}

// conditions created using GridDataCondition and add the condition to GridConditionalFormatDescriptor.

private Collection> ConditionFormats
{
get
{
GridDataCondition condition3 = new GridDataCondition(c => c.OrderID) { ConditionType = GridDataConditionType.Equals, Value = 10250 };
GridConditionalFormatDescriptor rowFormat = new GridConditionalFormatDescriptor();
rowFormat.Name = "condition1";
rowFormat.Conditions.Add(condition3);
rowFormat.Cell.HtmlAttributes["style"] = "background-color:#E29100";

Collection> cf = new Collection>();
cf.Add(rowFormat);
return cf;
}
}

Please find the sample from the following link :

http://www.syncfusion.com/downloads/Support/DirectTrac/86477/Sample-900465145.zip

Please let us know if you need any further assistance.

Regards,
Eswari.S






Administrator [Syncfusion]
Replied On December 1, 2011 08:17 AM

Hi Eswari,

Thanks for your help.

I know that on paging, POST method will call but I already mentioned conditional format in the view than why it's not reflecting.

Thanks
Alok Shah


Eswari S [Syncfusion]
Replied On December 2, 2011 01:35 AM

Hi Alok,

Thanks for your update.

While adding the conditional formatting in view , it will not reflect in post actions. In this scenario even if we have added the conditions in view , again we need to add the conditional formatting’s in controller after post actions which is used to rebind the formatting’s. Since we suggest you to use properties model formatting(controller) to avoid this.

We have prepared the sample in both Builder(view) and properties model(controller) conditional formatting. Please find the sample from the following link:

Builder Sample :

http://www.syncfusion.com/downloads/Support/DirectTrac/86477/Sample-900465145.zip

Steps :

#1: Call the Conditional formatting in view side :

<%=Html.Syncfusion().Grid("OrdersGrid")
. . . .
. . . . .
.ConditionalFormats(condition =>
{
var dictionary = new Dictionary();
dictionary.Add("style", "background-color:#E29100");
condition.Add(new GridConditionalFormatDescriptor
{
Name = "TfsTransfer",

Conditions = new System.Collections.ObjectModel.Collection>
{
new GridDataCondition(c => c.OrderID) { ConditionType = GridDataConditionType.Equals, Value = 10249 }
},

Cell = new GridCellFormatter { HtmlAttributes = dictionary }
%>

[AcceptVerbs(HttpVerbs.Post)]

public ActionResult Index(PagingParams args)
{
IEnumerable data = new NorthwindDataContext().Orders.ToList();
ActionResult result = data.GridActions();

// rebind the action again

var engine = result as GridHtmlActionResult;
engine.GridModel.ConditionalFormats = this.ConditionFormats;
return engine;
}

// conditions created using GridDataCondition and add the condition to GridConditionalFormatDescriptor.

private Collection ConditionFormats
{
get
{
GridDataCondition condition3 = new GridDataCondition(c => c.OrderID) { ConditionType = GridDataConditionType.Equals, Value = 10250 };
GridConditionalFormatDescriptor rowFormat = new GridConditionalFormatDescriptor();
rowFormat.Name = "condition1";
rowFormat.Conditions.Add(condition3);
rowFormat.Cell.HtmlAttributes["style"] = "background-color:#E29100";

Collection cf = new Collection();
cf.Add(rowFormat);
return cf;
}
}

Conditional formatting using Properties model(controller ):

http://www.syncfusion.com/downloads/Support/DirectTrac/88155/Sample775746893.zip

Steps :

1. Create conditions using GridDataCondition and add the condition to GridConditionalFormatDescriptor.

2. Add GridConditionalFormatDescriptor to GridPropertiesModel using ConditionalFormats property

public ActionResult Index()
{
GridPropertiesModel model =new GridPropertiesModel();
model.ConditionalFormats = this.ConditionFormats;
ViewData["OrdersGrid"] = model; // OrdersGrid is the Grid ID
var data = new NorthwindDataContext().Orders.ToList();
return View(data);
}

3. If you are using a paging/sorting action, rebind the ConditionalFormats property again to Grid in the post action


[AcceptVerbs(HttpVerbs.Post)]
public ActionResult Index(PagingParams args)
{
IEnumerable data = new NorthwindDataContext().Orders.ToList();
ActionResult result = data.GridActions< Order>();
var engineSource = result as GridHtmlActionResult;
engineSource.GridModel.ConditionalFormats = this.ConditionFormats;
return engineSource;
}

Please try this and let us know if you have any other queries.

Regards,
Eswari.S





CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.

;