This is a migrated thread and some comments may be shown as answers.

[Solved] Issues with template column and hidden fields

7 Answers 53 Views
Grid
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Murali
Top achievements
Rank 1
Murali asked on 31 Aug 2011, 08:10 AM
Hi,
I am trying to use values from a hidden html field. The hidden html field is populated using a template coumn. The column values are populated dynamically as shown beow:

@*

 

PARTIAL VIEW TO RENDER THE SEARCH GRID, TAKING DATATABLE VIEW AS INPUT.*@

 

@model CdcSoftware.Pivotal.ThinClient.Common.ViewModel.Search.

 

SearchViewModel

 

 

 

 

<script type="text/javascript">

 

 

 

function onDataBound() {

 

$(

 

this).show(); //show the grid when it is databound

 

}

 

 

function onLoad() {

 

$(

 

'tr', this).live('dblclick', function (e) {

 

 

 

var $tr = $(this);

 

 

 

var $tableID = $tr.find("input[name=TableID]").val();

 

alert($tableID);

 

 

// var listtype = $tr.find("input[name=ListType]").val();

 

 

 

// if (listtype == "SearchesList") {

 

 

 

// var $tableID = $tr.find("input[name=TableID]").val();

 

 

 

// var $searchID. = $tr.find("input[name=SearchID]").val();

 

 

 

// var args = [];

 

 

 

// args['table'] = $tableID;

 

 

 

// args['search'] = $searchID;

 

 

 

// args['srl'] = " ";

 

 

 

// args['doubleclick'] = "true";

 

 

 

// window.location.hash = "/Search/show?table=" + args['table'] + "&search=" + args['search'] + "&srl=" + args['srl'] + "&doubleclick=" + args['doubleclick'];

 

 

 

// }

 

})

}

 

 

</

 

 

script>

 

@(Html.Telerik().Grid(Model.searchData.SearchDataView)

.Name((

 

string)ViewData["Table"])

 

.HtmlAttributes(

 

new { style = "display:none" })

 

.Columns(columns =>

{

System.Collections.Generic.

 

Dictionary<string,string> clickableColumns = new Dictionary<string, string>();

 

System.Collections.Generic.

 

List<string> HiddenColumns = new List<string>();

 

 

 

 

foreach (var item1 in Model.searchData.SearchDataView.Table.Columns)

 

{

 

 

 

string Title = string.Empty;

 

 

 

 

foreach (var col in Model.ColumnDefinitions)

 

{

 

 

if (col.Name.Equals(((System.Data.DataColumn)(item1)).ColumnName))

 

{

 

Title = col.Label;

 

 

if (col.IsClickable) clickableColumns.Add(col.Name,col.Action);

 

 

 

if (col.IsHidden) HiddenColumns.Add(col.Name);

 

 

 

break;

 

}

}

 

 

string language = Request.UserLanguages[0];

 

System.Globalization.

 

CultureInfo cultureInfo = new System.Globalization.CultureInfo(language);

 

System.Globalization.

 

DateTimeFormatInfo info = cultureInfo.DateTimeFormat;

 

 

 

 

string format = "{0:" + info.ShortDatePattern + " " + info.LongTimePattern + "}";

 

 

 

if (((System.Data.DataColumn)(item1)).DataType.FullName == "System.DateTime")

 

{

columns.Bound(((System.Data.

 

DataColumn)(item1)).ColumnName).

 

Title(!

 

string.IsNullOrEmpty(Title) ? Title : ((System.Data.DataColumn)(item1)).ColumnName).Width("auto")

 

.Format(format);

}

 

 

else if (clickableColumns.ContainsKey(((System.Data.DataColumn)(item1)).ColumnName))

 

{

 

 

 

string action = clickableColumns[((System.Data.DataColumn)(item1)).ColumnName];

 

 

 

// if (((System.Data.DataColumn)(item)).DataType.FullName == "Foreign

 

columns.Bound(((System.Data.

 

DataColumn)(item1)).ColumnName)

 

.Template( @<text>

 

@Html.Hidden(

 

"TableID",@item1)

 

 

 

</text>)

.Title(!

 

string.IsNullOrEmpty(Title) ? Title : ((System.Data.DataColumn)(item1)).ColumnName)

 

.ClientTemplate(clickableColumns[((System.Data.

 

DataColumn)(item1)).ColumnName]);

 

 

 

}

 

 

else if (HiddenColumns.Contains(((System.Data.DataColumn)(item1)).ColumnName))

 

{

 

columns.Bound(((System.Data.

 

DataColumn)(item1)).ColumnName)

 

 

.Visible(

 

false);

 

 

}

 

 

else

 

{

columns.Bound(((System.Data.

 

DataColumn)(item1)).ColumnName).

 

Title(!

 

string.IsNullOrEmpty(Title) ? Title : ((System.Data.DataColumn)(item1)).ColumnName).Width("auto");

 

 

}

}

clickableColumns.Clear();

 

})

.ClientEvents(events => events.OnLoad(

 

"onLoad"))

 

.DataBinding(dataBinding => dataBinding.Ajax().Enabled(

 

true).Select(

 

 

 

"_CustomBinding",

 

 

 

"Search",

 

 

 

new {

 

TableName = (

 

string)ViewData["Table"],

 

SearchString = ((

 

string)ViewData["SearchString"]),

 

Search = ViewData[

 

"Search"],

 

Srl = ViewData[

 

"srl"],

 

SearchType = ViewData[

 

"SearchType"],

 

OperatorType = Model.searchDefinition.OperatorForBasicSearch,

ParamCollection = (Model.ParameterData)

}))

.Pageable(paging => paging.Total((

 

int)ViewData["Total"]))

 

.Sortable(sorting => sorting

.SortMode(

 

GridSortMode.SingleColumn))

 

 

.Scrollable(c => c.Height(

 

"auto"))

 

 

.Reorderable(reorder => reorder.Columns(

 

true))

 

.Resizable(resizing => resizing.Columns(

 

true))

 

.Groupable()

.EnableCustomBinding(

 

true)

 

.ClientEvents(e => e.OnDataBound(

 

"onDataBound"))

 

)

 



The problem that I am facing is that when i try accessing the hidden colum value in the double click live event it is returning a message "undefined".
What could be wrong?

Regards,
Murali

7 Answers, 1 is accepted

Sort by
0
Atanas Korchev
Telerik team
answered on 31 Aug 2011, 09:14 AM
Hi Murali,

 It seems that you have defined only the server side template to render a hidden field. Please configure the ClientTemplate to do the same as the latter is used during ajax binding.

Regards,
Atanas Korchev
the Telerik team

Thank you for being the most amazing .NET community! Your unfailing support is what helps us charge forward! We'd appreciate your vote for Telerik in this year's DevProConnections Awards. We are competing in mind-blowing 20 categories and every vote counts! VOTE for Telerik NOW >>

0
Murali
Top achievements
Rank 1
answered on 31 Aug 2011, 12:34 PM
Hi,
Can i please get an example of how to acheive this?
Regards,
Murali
0
Dimo
Telerik team
answered on 31 Aug 2011, 03:43 PM
Hello Murali,

Please check out our Client Template demo:

http://demos.telerik.com/aspnet-mvc/grid/templatesclientside

In case you need to use IF statements in the client template, here is how to do it:

http://www.telerik.com/community/forums/aspnet-mvc/grid/show-thumbnail-only-if-image-path-is-not-null.aspx#1598178

Regards,
Dimo
the Telerik team

Thank you for being the most amazing .NET community! Your unfailing support is what helps us charge forward! We'd appreciate your vote for Telerik in this year's DevProConnections Awards. We are competing in mind-blowing 20 categories and every vote counts! VOTE for Telerik NOW >>

0
Murali
Top achievements
Rank 1
answered on 02 Sep 2011, 07:45 AM
The problem that I am facing here is that on double click of a data row, I need to pass values to a javascript function that then handles this double click appropraitely. How do I do it with client template?
0
Dimo
Telerik team
answered on 02 Sep 2011, 08:48 AM
Hi Murali,

The client template is not directly related to the double-click user action, because you are using the live() jQuery method to subscribe to the event, so the handler should be executed no matter whether you click inside the client template or outside it. Can you be more specific what is unclear with regard to the client template usage in your case?

Regards,
Dimo
the Telerik team

Thank you for being the most amazing .NET community! Your unfailing support is what helps us charge forward! We'd appreciate your vote for Telerik in this year's DevProConnections Awards. We are competing in mind-blowing 20 categories and every vote counts! VOTE for Telerik NOW >>

0
Murali
Top achievements
Rank 1
answered on 02 Sep 2011, 08:56 AM
The problem i am facing is as follows:
The tables to which the grid is bound is decided at runtime. We are using the same grid to dynamically bind the grid to different tables based on user selection. User can select the table to which the grid needs to bind itself and the data relevant to that is shown in the grid.
On double click of a data row, we need to pick a couple of column values and pass it to another function that perfoms some action on it (Like opening a form based on passed in values). This is a javascript function.
How do I pass these coumn values on double click of a data row?

Regards,
Murali
0
Dimo
Telerik team
answered on 02 Sep 2011, 04:09 PM
Hello Murali,

Once you have the clicked row DOM element, you can use the dataItem method.

http://www.telerik.com/help/aspnet-mvc/telerik-ui-components-grid-client-api-and-events.html#dataItem

Best wishes,
Dimo
the Telerik team

Thank you for being the most amazing .NET community! Your unfailing support is what helps us charge forward! We'd appreciate your vote for Telerik in this year's DevProConnections Awards. We are competing in mind-blowing 20 categories and every vote counts! VOTE for Telerik NOW >>

Tags
Grid
Asked by
Murali
Top achievements
Rank 1
Answers by
Atanas Korchev
Telerik team
Murali
Top achievements
Rank 1
Dimo
Telerik team
Share this question
or