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. Image for the cookie policy date

Display columns mapping


Please find attached Code.txt file containing the sample code.

My model(Employee) has a property Person. When I try to map a property(First i.e. First Name) of Person, on the column in the view, it does not show up on the UI. All the other columns( ID, SSN, Salary) mapping directly to the property of Employee can be seen.

Clicking on column header to sort gives following exception: Error: 'this.get_columns()[...].MappingName' is null or not an object.

Kindly advise in case I am missing something?

Also, I would like to know if mapping the count of the collections defined within the Model is supported. e.g. If I have a List in my Model and want to display the count of Employees for each Company in my UI, do I need to do any special handling for the same?




Code_b7cb47ef.txt

5 Replies

ML Muthukumar L Syncfusion Team July 13, 2009 07:05 PM UTC

Hi Nimish,

Thanks for using Syncfusion products.

Column Mapping:

We regret to let you know that currently, we only support mapping Columns from complex model in controller.

Please refer the following code snippet for Complex type column mapping

View

[ASPX]
<%=Html.Grid("Sorting_Grid”,”EmployeeList” ) %>

Controller
[C#]
public ActionResult Index()
{
GridPropertiesModel model = new GridPropertiesModel
{
DataSource = new List {
new Employee {
ID = 1,
Salary = 100,
SSN = "123456789",
Name = new PersonName
{
First = "Nimish",
Last = "Bhonsale",
Middle = "S"
}
}
},
PagingSortingMapper = "SortPageAction",
AllowSorting = true,
Caption = "Employee List",
AllowPaging = true,
PageSize = 10,
PageCount = 10,
PrimaryKeyColumns = {"ID"}


};

ViewData["EmployeeList"] = model;
model.TableDescriptor.VisibleColumns.clear();

/// Columns can be mapped to the grid using visible columns collection
model.TableDescriptor.VisibleColumns.Add(“ID”);
model.TableDescriptor.Columns[0].HeaderText ("ID");

// Complex model columns can be mapped by ObjectType_PropertyName
// Property name “First” belongs to “Name” type.
model.TableDescriptor.VisibleColumns.Add(“Name_First”);

/// Visible columns collections don’t have Header Text property
/// HeaderText should be Specified using the Columns collection
model.TableDescriptor.Columns[3].HeaderText = "First Name";
model.TableDescriptor.VisibleColumns.Add(“SSN”);
model.TableDescriptor.Columns[1].HeaderText = "Social Security Number";
model.TableDescriptor.VisibleColumns.Add(“Salary”);
model.TableDescriptor.Columns[2].HeaderText = "Salary";
return View();
}

[AcceptVerbs(HttpVerbs.Post)]
public ActionResult SortPageAction()
{
IEnumerable data = new List
{
new Employee
{
ID = 1,
Salary = 100,
SSN = "123456789",
Name = new PersonName
{
First = "Nimish",
Last = "Bhonsale",
Middle = "S"
}
}
};
ActionResult result = data.GridActions();
var engineSource = result as GridHtmlActionResult;
engineSource.GridModel.TableDescriptor.VisibleColumns.clear();
engineSource.GridModel.TableDescriptor.VisibleColumns.Add(“ID”);
engineSource.GridModel.TableDescriptor.Columns[0].HeaderText ("ID");
engineSource.GridModel.TableDescriptor.VisibleColumns.Add(“Name_First”);
engineSource.GridModel.TableDescriptor.Columns[3].HeaderText = "First Name";
engineSource.GridModel.TableDescriptor.VisibleColumns.Add(“SSN”);
engineSource.GridModel.TableDescriptor.Columns[1].HeaderText = "Social Security Number";
engineSource.GridModel.TableDescriptor.VisibleColumns.Add(“Salary”);
engineSource.GridModel.TableDescriptor.Columns[2].HeaderText = "Salary";
return result;

}

I would like to know if mapping the count of the collections defined within the Model is supported. e.g. If I have a List in my Model and want to display the count of Employees for each Company in my UI, do I need to do any special handling for the same?


If Model Employee list is having Company column. We can group the Grid by Company column and use Summaries Feature number of employees for each country can be displayed.

Please refer our Summaries sample demo in the following link:

http://samples.syncfusion.com/mvcgriddemo/v7.3.0.18/summary/summaries

If this is not helpful please provide more information about this scenario which would help us to investigate and provide a this.

Thanks for your patience.

Thanks,
Muthukumar.L



DM Dan Miser August 31, 2009 05:01 AM UTC

Is there an update on how to do this with 7.303.0.20? The Grid method doesn't accept just 2 parameters. Thanks.


BM Balaji M Syncfusion Team September 1, 2009 11:21 AM UTC

Hi Miser,

Thank you for your interest in syncfusion products.

We regret to let you know that currently, we don't support complex type column mapping in view. We supports this complex type column mapping through controller. [the same previous solution works in version 7.303.0.20].

Please refer the sample from below link.
http://files.syncfusion.com/support/grid_mvc/Incidents/F87870/MvcSample.zip

Please let me know if you have any concerns.

Regards,
M.Balaji



LU Lukasz November 12, 2009 02:18 PM UTC

[ASPX]
<%=Html.Grid("Sorting_Grid”,”EmployeeList” ) %>


I can't compile this kind of code because in all 3 methods available -> Html.Grid() requires columns. What can I do about it?



BM Balaji M Syncfusion Team November 13, 2009 12:04 PM UTC

Hi Lukasz,

Thank you for your interest in Syncfusion product.

Our Essential Grid have been revamped to provide an enhanced support to extensive client side functionality. Due to revamping the reported helper is removed from Grid Extensions. Instead of this extension we can achieve this throw the following extension.

[view]

<%=Html.Grid("Grid1") %>


In this extension, we can send GridPropertiesModel values directly to the Grid using ViewData.

[Controller]

ViewData["Grid1"] = model;

Refer the below code snippet, which illustrates this.

[Controller]

public ActionResult Index()
{
GridPropertiesModel model = new GridPropertiesModel
{
DataSource = new NorthwindDBDataContext().Orders.Take(30),
Caption = "Order",
AllowPaging = true,
AllowSorting = true
};
model.TableDescriptor.VisibleColumns.Add("CustomerID");
model.TableDescriptor.VisibleColumns.Add("EmployeeID");
model.TableDescriptor.VisibleColumns.Add("OrderID");
model.TableDescriptor.VisibleColumns.Add("OrderDate");
model.TableDescriptor.VisibleColumns.Add("ShipCity");

ViewData["Grid1"] = model;
return View();
}

Please refer the sample from below link.
http://files.syncfusion.com/support/grid_mvc/Incidents/v7.4.0.20/F87870/MVC_GridSample.zip

We would also suggest you to refer the below documentation link for more details.

http://help.syncfusion.com/ug_74/GridMVC/defaultMVC.html

Please let me know if you have any concerns.

Regards,
M. Balaji.


Loader.
Live Chat Icon For mobile
Up arrow icon