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

Dynamic Model

Hi guys,
i'm trying to implement the Syncfusion MVC Grid an i have a problem with my dinamical model in the view.

In my product i have a model which returns a List of dynamical objects (i get the date from a thirth party, so i can't chage it and i won't to wrap it). Here the simple example:

public class Foo
{
public List getBoo()
{
List list = new List();
dynamic obj;

for (int i = 0; i < 15; i++)
{
obj = new System.Dynamic.ExpandoObject();
obj.aaa = "aaa";
obj.bbb = "bbb";
obj.ccc = "ccc";
obj.ddd = "ddd";
obj.eee = "eee";
list.Add(obj);
}
return list;
}
}

And here is the controller:

public ActionResult Grid()
{
Foo mod = new Foo();
var myMod = mod.getBoo();

GridPropertiesModel model = new GridPropertiesModel()
{
DataSource = myMod,
AllowPaging = true,
AllowSorting = true,
Caption = "All Bla's",
AutoFormat = Skins.Midnight,
AllowFiltering = true,
AllowGrouping = true,
Localize = System.Threading.Thread.CurrentThread.CurrentUICulture.Name,
LocalizationPath = "~/App_GlobalResources"
};

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

So my question is, how looks the view? Any ideas?
I try with:
@{

Html.Syncfusion().Grid("myDinamicalGrid", "GridModel",
column =>
{
column.Add(p => p.aaa).HeaderText("This is aaa");
column.Add(p => p.aaa).HeaderText("This is aaa");

});
}



17 Replies

BM Bala Murugan A.S Syncfusion Team March 20, 2012 07:20 AM UTC

Hi Petar Raykov,

Thanks for using Syncfusion Products.

Currently we do not provide 'support to binding dynamic objects'. This has been confirmed as a Feature Request.

We will implement this feature in our forthcoming new version releases or service pack releases.
We usually have an interval of at least three months between releases. The feature implementation
would also greatly depend on the factors such as product design, code compatibility and complexity.
We will get back to you once the feature is implemented.

Please let us know if you have any concerns.

Regards,
Bala Murugan A.S




PR Petar Raykov March 23, 2012 01:52 PM UTC

Hi Bala Murugan,

thank you for your post.
Is there any workarounds, that can i use?
I get the Model on runtime, so i can't create a model on the desing time.

Kind regards,
Petar Raykov



PR Petar Raykov March 27, 2012 07:14 AM UTC

Hi me again,

i have another idea but it doesn’t work too. I would like to have a model with only one property e.g. Values from Type String Array. For instance:

namespace MyNamespace.Models
{
public class TestObject
{
public string[] Values { get; set; }
}
}


The idea is to use a for-loop over the property inside the view. For instance:

@(new HtmlString(Html.Grid("Grid1","GridModel", columns =>
{
for(int i = 0; i < p.Values.Count; i++)
{
columns.Add(p => p.Values[i]);
}
}).ToString()

Is there any workaround?

Kind regards,
Petar Raykov






BM Bala Murugan A.S Syncfusion Team March 27, 2012 12:27 PM UTC

Hi Petar Raykov,

Thanks for the update.

Currently we are analyzing on your requirement with high priority. We will update you on March 29,2012.

Please let us know if you have any concerns.

Regards,
Bala Murugan A.S



BM Bala Murugan A.S Syncfusion Team March 29, 2012 04:14 PM UTC

Hi Petar Raykov,

Thanks for your patience,

We are tried on your requirement but there is no workaround available on binding object dynamically. We have prepared simple sample of binding objects to grid with a help of ITypedList and same can be downloaded from the below link.

Sample link: http://www.syncfusion.com/downloads/Support/DirectTrac/91680/DynamicModel-352789180.zip

Could you please have a look at the above sample and let us know if this sample meets your requirement of binding object to grid?

Please let us know if you have any concerns.

Regards,
Bala Murugan A.S




PR Petar Raykov April 2, 2012 06:31 AM UTC

Hi Bala,

unfortunately this isn't my intention.

I'm implementing a client of a server-client system. The data for the grid comes from the server component via WCF.
I get a table structure as Datatable() with header label and strongly typed values:

ID (int) | Name (string)| Property (int) | Date (date)
1 | lorem | 12 | 12.05.2012
2 | ipsum | 10 | 10.05.2012
3 | dolor | 24 | 14.05.2012

The big problem is, that I don't know the structure (heder names and types) on the DESIGN time, it depends on the server settings.

My intension was to use an ExpandoObject with dynamical properties so I can add them on the run time. As far as I understood the Syncfusion MVC Grid doesn’t support this .NET feature.
So my idea is to use an array, hashtable or datatable as a datacontainer.

The disadvantage of your example is, that the properties of Customer class you are using in your example are known on the design time and this is what I don’t know on the design time.

Kind regards,
Petar Raykov



HA Hatim April 5, 2012 11:45 AM UTC



BM Bala Murugan A.S Syncfusion Team April 11, 2012 04:34 AM UTC

Hi Petar Raykov

Thanks for the update.

We suggest you to refer our online help for your query. Please refer the below link to know about the Dynamic DataBinding in grid.

http://help.syncfusion.com/Ug_101/User%20Interface/ASP.NET%20MVC/Grid/documents/dynamicdatabinding.htm

Please let us know if you have any concerns.

Regards,
Bala Murugan A.S




BM Bharath M Syncfusion Team April 23, 2012 09:54 AM UTC

Hi Petar,

Thank you for your patience.

We have added the DataTable support for Grid [ASP.Net MVC] control. This is included in our Essential Studio Volume 2 release which is expected to be release on the last of April 2012.

Also, we have planned to implement the Dynamic Expando Object support in our next release. We will update you once it is implemented.

Let me know if you have any concerns.

Regards,
Bharath




GE German October 4, 2012 01:04 PM UTC

Hi Petar Raykov, I have the same problem with dynamic models. 
Did You solve the problem? 

I bind datatable to a sync grid, the columns names and count rows are good, but the row contents is not showing. 

Any idea?


RD Rakesh D Syncfusion Team October 8, 2012 12:43 PM UTC

Hi German,

Thanks for using Syncfusion Products. 

Query : Binding “Data table” to Syncfusion grid.

We are sorry for inconvenience caused. We are unable to reproduce the issue. We have prepared a simple sample, demonstrating the working of “ Binding data table to Syncfusion grid” and the same can be downloaded from the following link below.

Could you please try the sample and get back to us whether you are able to reproduce the issue? If not, could you please give more information or by reproducing the issue in the above sample so that we could sort out the issue and provide you with solution. The information provided would be of great help in resolving the issue.

 

Please let us know if you have any concerns. 

Regards,

Rakesh D

 



DataTable_293bb129.zip


GE German October 10, 2012 03:05 PM UTC

Thanks for the reply. 
Now I need to edit the datatable in the grid, but I have problems with DataRow Id, when I click in delete or add or edit, in de server method I'dont see de parameters or de editing row content

This is my code: My Id is "ObjectId"

DataTable:

public EnumerableRowCollection<DataRow> GetDataTable()
        {
            //
            // Here we create a DataTable with four columns.
            //
            DataTable table = new DataTable();
            table.Columns.Add("ObjectId", typeof(string));
            table.Columns.Add("Dosage", typeof(string));
            table.Columns.Add("Drug", typeof(string));
            table.Columns.Add("Patient", typeof(string));
            table.Columns.Add("Date", typeof(string));

            DataColumn[] key = new DataColumn[1];
            key[0] = table.Columns["ObjectId"];
            table.PrimaryKey = key;
            
            // Here we add five DataRows.
            //
            table.Rows.Add("1", 25, "Indocin", "David", DateTime.Now.ToShortDateString());
            table.Rows.Add("2", 50, "Enebrel", "Sam", DateTime.Now.ToShortDateString());
            table.Rows.Add("3", 10, "Hydralazine", "Christoff", DateTime.Now.ToShortDateString());
            table.Rows.Add("4", 21, "Combivent", "Janet", DateTime.Now.ToShortDateString());
            table.Rows.Add("5", 100, "Dilantin", "Melanie", DateTime.Now.ToShortDateString());
 
            return table.AsEnumerable();
        }

View:
<div style="width:100%;">
    @(Html.Syncfusion().Grid<DataRow>("JSONCRUD")
                        .Datasource((IEnumerable<DataRow>)ViewData["data"])
                        .AutoFormat(Skins.Marble)
                        .EnablePaging()
                        .EnableSorting()
                        .ActionMode(ActionMode.JSON)
                        .Caption(ViewData["RelationTitle"].ToString())
                        .ToolBar(tools => tools.Add(GridToolBarItems.AddNew)
                                              .Add(GridToolBarItems.Edit)
                                              .Add(GridToolBarItems.Delete)
                                              .Add(GridToolBarItems.Update)
                                              .Add(GridToolBarItems.Cancel))
                                             .Mappers(mapper => mapper.InsertAction("AddItem")
                                                                    .SaveAction("SaveItem")
                                                                    .DeleteAction("DeleteItem"))
                                            .Editing(edit =>
                                            {
                                                edit.AllowEdit(true)
                                                    .AllowNew(true)
                                                    .AllowDelete(true);
                                                edit.EditMode(GridEditMode.Normal);
                                                edit.PrimaryKey(key => key.Add(p => p.Table.PrimaryKey));
                                                
                                            }))
</div>

And my controller

   [AcceptVerbs(HttpVerbs.Post)]
        public ActionResult EditableRelationGrid(PagingParams args)
        {
            IEnumerable data = GetDataTable();
            return data.GridJSONActions<DataRow>();
        }

        [AcceptVerbs(HttpVerbs.Post)]
        public ActionResult SaveItem(DataRow row)
        {
            _moreObjectManager.Update(row);
            var data = GetDataTable();
            return data.GridJSONActions<DataRow>();
        }

        [AcceptVerbs(HttpVerbs.Post)]
        public ActionResult AddItem(DataRow row)
        {
           _moreObjectManager.Add(row);
            var data = GetDataTable();
            return data.GridJSONActions<DataRow>();
        }

        [AcceptVerbs(HttpVerbs.Post)]
        public ActionResult DeleteItem(string rowId)
        {
           _moreObjectManager.Delete(rowId);
            var data = GetDataTable();
            return data.GridJSONActions<DataRow>();
        }





RD Rakesh D Syncfusion Team October 15, 2012 12:54 PM UTC

Hi German,

 

Thanks for using Syncfusion Products.

 

Query 1: To edit the datatable in the grid.

 

We have noticed that you have used “ edit.PrimaryKey(key => key.Add(p => p.Table.PrimaryKey)); “ in your view page to specify the Primary Key property for grid. We suggest you to use the below code snippet for setting primary key.

 

[view]

.Editing(edit =>{

                     edit.PrimaryKey(new string[]{"ObjectId"});

})

 

For your convenience we have your modified your codes and created a sample for performing editing, deleting, adding operations in grid using datatable binding. Please try the below sample and let us know if you have any concerns.

 

Regards,

Rakesh D

 



DataTable_d81341da.zip


GE German October 23, 2012 06:44 PM UTC

HI, thanks for reply and sample, but you don't understood what is an "dynamic model".

The functions in your sample isn't dynamic, because columns are fixed in save,edit, methods. 
In the same page and grid I need to bind datatables with different count of columns, all of this, generated by code in runtime, so, I don't know de name of de columns or de count of this at design time: 
    
Your example works fine, but It isn't dynamic datatable, and It isn't dynamic count of columns.

 Now, when I used a datable to bind a grid, I see "column name" property of "datacolumn" in header text, and not column caption. Is it supporting in the Syncfusion grid?


RD Rakesh D Syncfusion Team October 26, 2012 03:20 AM UTC

Hi German,

Thanks for using Syncfusion Products.

Query 1: To edit the datatable in the grid.

We suggest you to use the below code snippet for setting primary key.

[view]

.Editing(edit =>{

                  edit.PrimaryKey(new string[]{"ObjectId"});

})

Query 2: To set Column caption or HeaderText.

To set column caption or HeaderText we suggest you to use HeaderText property of column. Please refer below code snippet for further details.

.Column(col =>{col.Add("ObjectId").HeaderText("OBJECT ID");})

For your convenience we have your modified your codes and created a sample for performing editing, deleting, adding operations in grid using datatable binding. Please try the below sample and let us know if you have any concerns.

Regards,

Rakesh D

 



Datatable binding_7046c219.zip


PG Pramod Gaikwad February 11, 2016 01:04 PM UTC

Hello ,

I want to achieve following dynamically without specify model Name for List in Batch Update .

 public ActionResult BatchUpdate(string tablename, List<object> changed, List<object> added, List<object> deleted)
        {
        
       // Update Opearation

     }

I use this then I got Changed -{object}
So give me Idea to achieve result without specify model Name



KN Kavitha Narayanan Syncfusion Team February 15, 2016 11:47 AM UTC

Hi Pramod,


We considered this “Editing support for dynamic data binding” as a feature request and a support incident has been created under your account to track the status of this requirement. Please log on to our support website to check for further updates.


https://www.syncfusion.com/account/login?ReturnUrl=/support/directtrac/incidents


Regards,

Kavitha N.


Loader.
Live Chat Icon For mobile
Up arrow icon