0
$("#TransactionTable").DataTable({
                    ajax: {
                        url: '/Transaction/SearchMockup',
                        type: 'POST',
                        data: {
                            cardEndingWith: $("#ccn").val(),
                            status: $("#status").val(),
                            supplier: $("#supplier").val(),
                            fromDate: $("#fromDate").val(),
                            toDate: $("#toDate").val()
                        }
                    },
                    columns: [
                    {
                    { data: 'Status' },
                    { data: 'TransactionId' },
                    { data: 'CreditCardNumber' },
                    { data: 'Supplier' },
                    { data: 'CreatedAt' },
                    { data: 'Amount' },
                    { data: 'Guid' }
                    ],
                    columnDefs: [
                    {
                        "targets": [6],
                        "visible": false,
                        "className": "guid"
                    },
                    {
                        "targets": [1],
                        "className": "transactionIdColumn",
                    }
                    ]
                });

Have that table definition, want on click at "TransactionId" column, to get the value/data of the hidden "Guid" column. My guid column have class name called "transactionIdColumn" as you can see. Need help with the jQuery Code.

Try to do something like this:

$("#TransactionTable .transactionIdColumn").on('click', function (elm) {
                var guidNumber = $(elm).closest("tr").find(".transactionIdColumn").html();
                alert(guidNumber);
            });

enter image description here

2
  • 1
    As written, var guidNumber = $(elm).closest("tr").find(".transactionIdColumn").html(); looks to be equivalent to var guidNumber = $(this).html();. Changing that .find() selector should give you a fighting chance. Commented Aug 2, 2017 at 15:16
  • 1
    Use the datatable api to access the data ... see stackoverflow.com/a/36695886/1175966 Commented Aug 2, 2017 at 15:17

1 Answer 1

1

you can try this.

{ "data"  : "TransactionId",
  "render": function (data, type, full, meta) {
              var guid = full['guid'];
              return '<a href="#" class="trans_id" data-guid="'+guid+'"> '+data+' </a>';
            }
},

Here is the link to the datatables.render

 $("#TransactionTable .trans_id").on('click', function (elm) {
     var guidNumber = $(this).data('guid');
     alert(guidNumber);
 });
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.