Chiragkumar Thakar
Chiragkumar Thakar

Reputation: 3716

Get selected value from label/Datatable

I need help in getting selected value either from data-table(Jquery plugin) cell or from a label, below I have attached a file which will help to understand the requirements.

I was looking for Jquery plugin to implement this, but I couldn't find much.

Help would be appreciated. :)

https://ufile.io/nvmci

Upvotes: 1

Views: 187

Answers (1)

Chiragkumar Thakar
Chiragkumar Thakar

Reputation: 3716

I have got a solution for the given issue.

Javascript itself provides functionality to get the selected value from the document by using window.getSelection(); or document.getSelection();

What I have tried and it works for me.

if (!window.x) {
    x = {};
}

x.Selector = {};
x.Selector.getSelected = function() {
    var t = '';
    if (window.getSelection) {
        t = window.getSelection();
    } else if (document.getSelection) {
        t = document.getSelection();
    } else if (document.selection) {
        t = document.selection.createRange().text;
    }
    return t;
}

$(document).ready(function() {
    $(document).bind("mouseup", function() {
        var mytext = x.Selector.getSelected();
        alert(mytext);
    });
});

http://jsfiddle.net/YstZn/1/

Upvotes: 2

Related Questions