Pawan
Pawan

Reputation: 32331

How to read first 3 column values of a table

I am using TableSorter .

Once i click on the sort on Employee Id , it displays records as per Employee Id in order .

All this is working fine .

http://jsfiddle.net/4mVfu/4864/

On click of a button , is it possible to get the first 3 Names as a comma seperated string ?? For example mohan,raj,Madhu as output

This is my code

function formSalesTable(response) {
    $("#salestablebody").html("");
    if (response.length > 0) {
        var html = '';
        for (var i = 0; i < response.length; i++) {
            var emp_name = response[i].appUserName.trim();
            var emp_depotName = response[i].emp_ID.trim();
            html += '<tr>\
            <td class="text-center"></td>\n\
            <td>' + emp_name + '</td>\n\
            <td>' + emp_depotName + '</td>\n\
            </tr>';
        }
        $("#salestablebody").html(html);
        $("#salesuserstable").tablesorter();
        $("#salesuserstable").trigger('update');

    }
}

Could you please let me know how to read first 3 values after clicking on the sorting on Employee Id

Upvotes: 0

Views: 44

Answers (1)

Balachandran
Balachandran

Reputation: 9637

use map() to get the value in single array

 var name = $("#salestablebody tr td:nth-child(2):lt(3)").map(function () {
        return $(this).text();
    }).get();
  console.log(name.join(","))

DEMO

Upvotes: 4

Related Questions