4 Answers, 1 is accepted
0
Shinu
Top achievements
Rank 2
answered on 25 Apr 2014, 11:55 AM
Hi Shweta,
I guess that you want to truncate the GridTemplateColumn Text, please have a look into the sample code snippet which works fine at my end.
ASPX:
JavaScript:
Please elaborate your requirement if it doesn't help.
Thanks,
Shinu.
I guess that you want to truncate the GridTemplateColumn Text, please have a look into the sample code snippet which works fine at my end.
ASPX:
<
telerik:RadGrid
ID
=
"RadGrid1"
runat
=
"server"
DataSourceID
=
"SqlDataSource1"
AutoGenerateColumns
=
"false"
>
<
MasterTableView
>
<
Columns
>
<
telerik:GridTemplateColumn
DataField
=
"ShipName"
UniqueName
=
"ShipName"
HeaderText
=
"ShipName"
>
<
ItemTemplate
>
<
asp:Label
ID
=
"Label1"
runat
=
"server"
Text='<%# Eval("ShipName")%>'
</
asp:Label
>
</
ItemTemplate
>
</
telerik:GridTemplateColumn
>
</
Columns
>
</
MasterTableView
>
</
telerik:RadGrid
>
JavaScript:
<script type=
"text/javascript"
>
function
pageLoad() {
var
grid = $find(
"<%= RadGrid1.ClientID %>"
);
if
(grid) {
var
MasterTable = grid.get_masterTableView();
var
Rows = MasterTable.get_dataItems();
for
(
var
i = 0; i < Rows.length; i++) {
var
row = Rows[i];
var
label = row.findElement(
"Label1"
);
var
textvalue = label.innerText;
if
(textvalue.length > 5) {
textvalue = textvalue.substring(0, 5);
}
label.innerText = textvalue;
}
}
}
</script>
Please elaborate your requirement if it doesn't help.
Thanks,
Shinu.
0
Shweta
Top achievements
Rank 1
answered on 25 Apr 2014, 12:50 PM
Hi Shinu,
Thanks for the reply.
But I don't want to truncate the text depending on its length. I want to display it up to 3 lines,whatever its length will be then. Remaining text will be truncated.
Thanks for the reply.
But I don't want to truncate the text depending on its length. I want to display it up to 3 lines,whatever its length will be then. Remaining text will be truncated.
0
Shweta
Top achievements
Rank 1
answered on 25 Apr 2014, 12:51 PM
Hi Shinu,
Thanks for the reply.
But I don't want to truncate the text depending on its length. I want to display it up to 3 lines,whatever its length will be then. Remaining text will be truncated.
Thanks,
Shweta
Thanks for the reply.
But I don't want to truncate the text depending on its length. I want to display it up to 3 lines,whatever its length will be then. Remaining text will be truncated.
Thanks,
Shweta
0
Shinu
Top achievements
Rank 2
answered on 28 Apr 2014, 09:01 AM
Hi Shweta,
Please try the following sample code snippet which works fine at my end. As a suggestion you can take the length of the text and truncate the text as follows.
ASPX:
JavaScript:
Hope this will helps you.
Thanks,
Shinu.
Please try the following sample code snippet which works fine at my end. As a suggestion you can take the length of the text and truncate the text as follows.
ASPX:
<
telerik:RadGrid
ID
=
"RadGrid1"
runat
=
"server"
DataSourceID
=
"SqlDataSource1"
AutoGenerateColumns
=
"false"
Width
=
"100px"
>
<
MasterTableView
>
<
Columns
>
<
telerik:GridBoundColumn
DataField
=
"id"
UniqueName
=
"id"
HeaderText
=
"id"
>
</
telerik:GridBoundColumn
>
<
telerik:GridTemplateColumn
DataField
=
"LargeData"
UniqueName
=
"LargeData"
HeaderText
=
"LargeData"
>
<
ItemTemplate
>
<
asp:Label
ID
=
"Label1"
runat
=
"server"
Text='<%# Eval("LargeData")%>'></
asp:Label
>
</
ItemTemplate
>
</
telerik:GridTemplateColumn
>
</
Columns
>
</
MasterTableView
>
</
telerik:RadGrid
>
JavaScript:
<script type=
"text/javascript"
>
function
pageLoad() {
var
grid = $find(
"<%= RadGrid1.ClientID %>"
);
if
(grid) {
var
MasterTable = grid.get_masterTableView();
var
Rows = MasterTable.get_dataItems();
for
(
var
i = 0; i < Rows.length; i++) {
var
row = Rows[i];
var
label = row.findElement(
"Label1"
);
var
textvalue = label.innerText;
if
(textvalue.length > 60) {
//according to your scenario you can change the substring values
label.innerText = textvalue.substring(0, 35);
}
}
}
}
</script>
Hope this will helps you.
Thanks,
Shinu.