attached is my sample project where i'm trying to bind the grid with Json list and I'm not defining columns for grid.
Atanas from telerik team write some comment at below link for this feature, will this feature available or is there any way to do as my columns are decided at run time.
http://www.telerik.com/community/forums/aspnet-mvc/grid/bind-grid-to-json-object.aspx
Please help..
9 Answers, 1 is accepted
could some one comment on this?
pleasew help
The grid needs to have predefined columns in order to be bound. Generating the columns in runtime on the client-side is not currently supported. As I said in the other forum thread we may implement it once there is more demand for auto generated columns on the client-side.
Regards,Atanas Korchev
the Telerik team
i'm looking for some alternate to hide columns..situation is like below.... there are 4 columns (col1 to col4).
if user select option 1 then show col1 & col2 ..... and if user select option 2 , then show col3 & col4.
all i'm doing through Json call...no postbak.
i able to do some by below code to show/hide the column, but once any column hide/show for option 1, then it will remain same for option 2..it works only first time...
is there any way to do like this...please help
@(Html.Telerik().Grid<
BHN.PayGo.ASP.Model.Reports.HierarchyModel
>()
.Name("grdHierarchyContactInfo")
.Columns(columns =>
{
if (BHN.PayGo.ASP.Model.Reports.HierarchyModel.col1Show)
{
columns.Bound(o => o.AccountName).Title("Account Name").Width(75);
}
columns.Bound(o => o.AccountID).Title("Account ID").Width(75);
columns.Bound(o => o.AccountType).Title("Account Type").Width(75);
columns.Bound(o => o.Street1);
columns.Bound(o => o.Street2);
columns.Bound(o => o.City);
columns.Bound(o => o.State);
columns.Bound(o => o.Zip);
columns.Bound(o => o.Phone1);
columns.Bound(o => o.Phone2);
columns.Bound(o => o.Fax);
columns.Bound(o => o.Email);
columns.Bound(o => o.TestAccount);
columns.Bound(o => o.COL1);
columns.Bound(o => o.COL2);
columns.Bound(o => o.COL3);
columns.Bound(o => o.COL4);
columns.Bound(o => o.COL5);
columns.Bound(o => o.COL6);
columns.Bound(o => o.COL7);
})
.ClientEvents(events => events.OnDataBinding("onDataBindingContactInfo"))
.Sortable()
.Pageable()
.Scrollable(scrolling => scrolling.Enabled(true)))
//grid variables
var gridContactInfo = $('#grdHierarchyContactInfo').data('tGrid');
//account details type
var AccountDetailsType = $("input:radio[name='AccountDetails']:checked").val();
//get JSON data from the repective controller action
//input parameter for controller's action is grid current page (always 1) and the page size
$.getJSON('@Url.Action("HierarchyData", "Reports")', { pageNum: 1, pageSize: 10, accountDetailsType: AccountDetailsType }, function (result) {
//total number of records
totalRecords = result.total;
//total records
records = result.data;
//bindGridContactInfo();
gridContactInfo.dataBind(records);
//set the grid to page 1
gridContactInfo.currentPage = 1;
I can suggest an easier approach because hiding columns on the client-side may cause problems (cross browser issues).
You can define more than one grid and show the required grid using jQuery.show(). To hide a grid simply set its display property to none:
Html.Telerik().Grid().HtmlAttributes( new { style = "display:none" } )
Then using jQuery.show you can easily show the right grid and hide the other grid.
Regards,
the Telerik team
is there any other option through client side?
Thanks for help.
I can't think of any other option right now. The grid just does not support your requirement right now.
Regards,
the Telerik team
BTW, when this feature will be available?
This feature is not scheduled for implementation yet so I cannot give a specific answer when it will be ready. Our roadmap for the next release is available here.
All the best,Atanas Korchev
the Telerik team
Thanks