Jquery DataTable get data from row selected on click of button -


i trying have edit button @ top of datatable pick value current selected row , append url.

i have managed working not quite how have liked.

my edit button not using datatable value stored in data table.

    $.fn.datatable.ext.buttons.edit = {     text: 'edit',     action: function () {         var assetid;         $("#example tr.selected").each(function (index, row) {             assetid = ($(row).find("td:nth-child(2)").html());         });         if (assetid != null) {             var url = "/demo/edit/" + assetid;             window.location.href = url;         }     } }; 

example datatable site of table button shouts out data in current selected row. data tidier , datatable self.

$(document).ready(function() { var events = $('#events'); var table = $('#example').datatable( {     dom: 'bfrtip',     select: true,     buttons: [         "edit", //my edit button works requires external script         { // example button website.             text: 'get selected data',             action: function () {                 var count = table.rows( { selected: true } ).count();               //var count = table.rows( { selected: true } ).data();               // how drill down count value column 2.                 events.prepend( '<div>'+count+' row(s) selected</div>' );             }         }     ]  } );  } ); 

i have tried many ways try , access object within example datatables website can not value specific column in selected row using methods.

any appreciated.

i'll post pre-emptive answer comment left. if can stand doing without using datatables create , bind functions, can jquery , make own button.

the thing is, i'm not sure how you're getting 'selected'. part of datatables (i've used dt lot, never row select stuff)?

either way, applies class row, , use can use class select.

<button type="button" id="selected_action">do it!</button>   $('#selected_action').on('click', function(){      $('selected').each(function(){           parent_row = $(this).closest('tr');          //use nth-child selectors on parent_row want       }) }) 

if render button inside datatables, use selector though:

('#dc_{{dgroup.order}}_dlist tbody').on('click', '#selected_action', function(){...}); 

Comments

Popular posts from this blog

asynchronous - C# WinSCP .NET assembly: How to upload multiple files asynchronously -

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -