When a row is selected in Angular UI-Grid, copy the data from that row onto the clipboard

In need of a function to copy an entire row's data to the clipboard with a simple click. I have a Plunker link where I can only copy cell text:

http://plnkr.co/edit/EVrB5Ib9ZuqhbAMsV9Eg?p=preview

Below is the pseudocode for the Grid Options:

$scope.gridOptions = {
    data: 'data',
    enableRowSelection: true,
    enableFullRowSelection: true,
    enableHighlighting: true,
    multiSelect: false,
    enableRowHeaderSelection: false
};

When clicking on the second row, both 'A1' and 'B1' should be copied and pasted into a notepad or other application.

https://i.sstatic.net/zNVA4.png

Answer №1

To tackle this problem, you'll need to follow a few steps. First, you must register the rowSelectionChanged event handler to detect any changes in selection. Here's an example:

$scope.gridOptions.onRegisterApi = function(gridApi) {
  $scope.gridApi = gridApi;
  gridApi.selection.on.rowSelectionChanged($scope,function(row){
    if(row.isSelected) {
      // copy row.entity data to clipboard
    }
  });
}

I haven't personally worked with accessing the clipboard in AngularJS before. It seems like this package could be a potential solution, but there might be other alternatives available.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Content located on the right-hand side of the menu

I am currently working on a vertical navigation menu design, but I am facing some issues with aligning the text to start from the very left edge of the element. HTML <div class="jobs-links"> <ul> <li><a href="renovations. ...

Concealing axis lines within the initial circular grid or opting not to include them

Is there a way to incorporate some whitespace within the center circle of the radar chart? I'm aiming for the axis to commence at 1 radius (the initial circular line) or perhaps have the stoke set to 0 for the primary radius. Any assistance would be g ...

Tips for eliminating flutter for static menu with easyResponsiveTabs.js

Experiencing a flickering issue with the fixed menubar and easyResponsiveTabs.js in my project when scrolling down. Attempted to resolve it using jquery.noConflict(), but without success. Would appreciate any guidance on how to address this problem. ...

Ways to integrate a stateful button from Bootstrap into an Angular application

While it's easy to implement a "Loading" state when clicking on a button using Bootstrap, I couldn't find a simple way to do it in Angular with the Angular Bootstrap UI library. Any suggestions or tips would be greatly appreciated! ...

Adjust the increment value for ngRepeat

My current HTML template uses ngRepeat to display tiles on the page. <div ng-repeat="product in productList"> <div class="product-tile"> Product content is displayed here... </div> </div> Now, the designer requires ...

Angular's Motion Module

Incorporating Angular-5 into my project has introduced a plethora of animations on various pages. While the utilization of jQuery provides a straightforward approach for adding and removing classes to DOM elements, it is frequently advised against using jQ ...

How to disable an anchor tag based on a condition using ng-class?

I have a displayed table that includes a column called count which has an <a> tag with a href to a page. I want to show a link for all rows where count > 0 and disable it when count=0. I attempted to use AngularJS - ng-disabled not working for An ...

AngularJS constants are values that can be accessed and

Is it feasible to inject one constant into another constant using AngularJS? For example: var app = angular.module('myApp'); app.constant('foo', { message: "Hello" } ); app.constant('bar', ['foo', function(foo) ...

No matter what I try, connecting the CSS file to my HTML file just won't seem to work

I've been attempting to connect a CSS file to my HTML index file, but I can't seem to get it to work no matter what I try. I'm using VSCode. When typing the link from scratch, it auto-completes or shows up, indicating that it recognizes it. ...

Applying a CSS border to a div that perfectly encloses a span, adjusting to the

My goal is to create a nested structure where a div contains a span element like this: ---------- |Sentence| ---------- ----------------- |It's a looooong| |sentence | ----------------- While it works well for short sentences, long ones end u ...

Toggle the visibility of the data depending on the dropdown option chosen

Currently, I am developing an AngularJS application and facing a requirement to toggle the visibility of data based on the selected value in a dropdown list. Specifically, if the user chooses "Show" from the dropdown, the content within a tab should be dis ...

AngularJS throws the error message "$digest already in progress" upon logging out

When a user logs out, I would like to automatically redirect them to the main page. $rootScope.logOut = function() { myService.logOut().then(function(data) { $rootScope.$apply(function() { $location.path("/"); }); }); } However ...

Creating dynamic radio buttons in AngularJS

How can I create dynamic radio buttons in angularjs, using mobile numbers from this json array? challengeSelectInfo: [ {"mob_0" : "xxxxx1211"}, {"mob_1" : "xxxxx1211"}, {"mob_2" : "xxxxx1211"} ] I attempted to use ng-repeat and loop through c ...

Leveraging an AngularJS variable within an iframe

Is it possible to use a variable inside an iframe src or ng-src attribute? I've tried different variables but none seem to be recognized. For example: <iframe ng-src="http://www.example.com/?name={{test}}"> </iframe> The variable test ju ...

The navigation bar alignment to the right is malfunctioning

I'm puzzled as to why the navbar-right class is not properly closing out the two navigation bar elements on the right. Despite adding the correct code, it doesn't seem to be working as expected. <nav class="navbar fixed-top navbar-toggleable- ...

Dynamic Bootstrap Table with Fixed Header

I am customizing a Bootstrap table by adding CSS for a sticky header. My code snippet includes the following: .table-sticky th { background: #fff; position: sticky; top: -1px; z-index: 990; } <div class ...

What could be causing the lack of downward rotation of my arrow in css? (specifically, the span element)

<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=de ...

Customizing background size for iOS devices

This morning, I delved into research on a particular issue. Currently, I am crafting a single-page website that heavily relies on images. While Safari is usually criticized for its quirky handling of background-attachment:fixed, it seems to be working fine ...

What could be the reason for scrapy not returning any URLs?

Recently, I attempted to develop a tool to simplify my apartment search and access relevant information quickly (the website is not very user-friendly). However, I have encountered an issue and I may be overlooking something obvious...or perhaps I'm j ...

The <hr> tag is not displaying properly within the <option> element

I'm facing an issue with a selection element in my Vue project <div class="resultContainer"> <section> <option class="resultBtn" v-for="exchange in finalExchanges"> {{exchange}} <hr></option> </section> ...