I have a grid and a commanditem template of a button. On button click I want to copy the contents of the grid to the clipboard. I have a client settings on-command call to buttonclicked and it is not firing.
I am iterating on the client side through the grid and i concatenate to one large string. I have 4 columns, so I am putting each column followed by a tab, and then at the end of each row a new line. Then I will write this string out to the clipboard. I tried doing it on the server, and the string was built, but I could not access the clipboard on the server side, so I am trying to write the code on the client. The grid I am trying to copy is a template inside a tooltip.
I have a client settings on-command and it doesnt fire the javascript when I click the button( which is a command item). I put in a clientevent on key press, and it actually works if I highlight and press a key, but not on command(which is where my button is) Here is the aspx:
<telerik:RadToolTip runat="server" ID="RadToolTip2" TargetControlID="Label1"
Skin="Inox" ShowDelay="500" AutoCloseDelay="200000" Font-Names="arial"
Font-Size="XX-Large" BorderStyle="Inset" HideDelay="100000" ManualClose="False"
Position="BottomRight" Sticky="True" Width="300">
<telerik:RadGrid ID="toolTipUsers" runat="server" DataSourceID="ContentCentralActiveUsers"
GridLines="None" Skin="Default" AutoGenerateColumns="False"
commanditemdisplay="Top">
<MasterTableView DataSourceID="ContentCentralActiveUsers" CommandItemDisplay="Top" NoMasterRecordsText="No users to display."
GridLines="None" ItemStyle-Wrap="false" >
<CommandItemTemplate>
<asp:Button ID="copy" runat="server" CommandName="Copy" Text="Copy to clipboard" >
</asp:Button>
</CommandItemTemplate>
<ItemStyle Font-Size="Larger" Wrap="false"/>
<AlternatingItemStyle Font-Size="Larger" Wrap="false" />
<Columns>
<telerik:GridBoundColumn DataField="login_name" HeaderText="User name" UniqueName="username" ></telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="password" HeaderText="Password" UniqueName="password" ></telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="email" HeaderText="Email" UniqueName="email" ></telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="package_name" HeaderText="Package" UniqueName="package" ></telerik:GridBoundColumn>
</Columns>
</MasterTableView>
<ClientSettings ClientEvents-OnCommand="ButtonClicked"></ClientSettings>
</telerik:RadGrid>
</telerik:RadToolTip>
and here is the javascript:
function ButtonClicked(sender, args) {
var grid = sender;
var MasterTable = grid.get_masterTableView();
var rows = MasterTable.get_dataItems();
var cell;
var username;
var password;
var email;
var spackage;
var copyString;
copyString = "User name \t Password \t Email \t Package \r\n";
for (var i = 0; i < rows.length; i++) {
var row = rows[i];
cell = MasterTable.getCellByColumnUniqueName(row, "username");
username = cell.innerHTML;
cell = MasterTable.getCellByColumnUniqueName(row, "password");
password = cell.innerHTML;
cell = MasterTable.getCellByColumnUniqueName(row, "email");
email = cell.innerHTML;
cell = MasterTable.getCellByColumnUniqueName(row, "package");
spackage = cell.innerHTML;
copyString = copyString + username +"\t"+password+"\t"+email+"\t"+spackage+"\r\n";
}
window.clipboardData.setData('text', copyString);
}
I am iterating on the client side through the grid and i concatenate to one large string. I have 4 columns, so I am putting each column followed by a tab, and then at the end of each row a new line. Then I will write this string out to the clipboard. I tried doing it on the server, and the string was built, but I could not access the clipboard on the server side, so I am trying to write the code on the client. The grid I am trying to copy is a template inside a tooltip.
I have a client settings on-command and it doesnt fire the javascript when I click the button( which is a command item). I put in a clientevent on key press, and it actually works if I highlight and press a key, but not on command(which is where my button is) Here is the aspx:
<telerik:RadToolTip runat="server" ID="RadToolTip2" TargetControlID="Label1"
Skin="Inox" ShowDelay="500" AutoCloseDelay="200000" Font-Names="arial"
Font-Size="XX-Large" BorderStyle="Inset" HideDelay="100000" ManualClose="False"
Position="BottomRight" Sticky="True" Width="300">
<telerik:RadGrid ID="toolTipUsers" runat="server" DataSourceID="ContentCentralActiveUsers"
GridLines="None" Skin="Default" AutoGenerateColumns="False"
commanditemdisplay="Top">
<MasterTableView DataSourceID="ContentCentralActiveUsers" CommandItemDisplay="Top" NoMasterRecordsText="No users to display."
GridLines="None" ItemStyle-Wrap="false" >
<CommandItemTemplate>
<asp:Button ID="copy" runat="server" CommandName="Copy" Text="Copy to clipboard" >
</asp:Button>
</CommandItemTemplate>
<ItemStyle Font-Size="Larger" Wrap="false"/>
<AlternatingItemStyle Font-Size="Larger" Wrap="false" />
<Columns>
<telerik:GridBoundColumn DataField="login_name" HeaderText="User name" UniqueName="username" ></telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="password" HeaderText="Password" UniqueName="password" ></telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="email" HeaderText="Email" UniqueName="email" ></telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="package_name" HeaderText="Package" UniqueName="package" ></telerik:GridBoundColumn>
</Columns>
</MasterTableView>
<ClientSettings ClientEvents-OnCommand="ButtonClicked"></ClientSettings>
</telerik:RadGrid>
</telerik:RadToolTip>
and here is the javascript:
function ButtonClicked(sender, args) {
var grid = sender;
var MasterTable = grid.get_masterTableView();
var rows = MasterTable.get_dataItems();
var cell;
var username;
var password;
var email;
var spackage;
var copyString;
copyString = "User name \t Password \t Email \t Package \r\n";
for (var i = 0; i < rows.length; i++) {
var row = rows[i];
cell = MasterTable.getCellByColumnUniqueName(row, "username");
username = cell.innerHTML;
cell = MasterTable.getCellByColumnUniqueName(row, "password");
password = cell.innerHTML;
cell = MasterTable.getCellByColumnUniqueName(row, "email");
email = cell.innerHTML;
cell = MasterTable.getCellByColumnUniqueName(row, "package");
spackage = cell.innerHTML;
copyString = copyString + username +"\t"+password+"\t"+email+"\t"+spackage+"\r\n";
}
window.clipboardData.setData('text', copyString);
}