var table = $("#example").DataTable(
{
select:true,
scroller:true,
scrollY:300,
deferRender:true,
rowReorder:false,
columnDefs:[
{"targets":6,
"visible":false
}]
});
var $selectedData = $("#selectedData");
table.column(0).data().each(function (val,index) {
console.log("data index :"+index+" value:"+val);
});
/*$("#example tbody").on("click","tr",function() {
var val = $(this).toggleClass('selected');
});
*/
table.on("select",function(e,dt,type,index) {
console.log("the type is:"+type+" and dt is:"+dt+" index is--->"+index);
table[ type ]( index ).nodes().to$().addClass( 'custom-selected' );
if(type === "row") {
var data = table.rows(index).data().pluck(0);
var position = table.rows(index).data().pluck(1);
var guid = table.rows(index).data().pluck(6);
console.log("the name is :"+data[0]+" "+position[0]);
$selectedData.html("<p>"+data[0]+" "+position[0]+"</p>");
console.log("the index is:"+index);
console.log("the guid that we should save is :"+guid[0]);
}
});
$("#button").on("click",function() {
table.rows().deselect();
//table.row(':eq(15)').select();
var guidVal = $("#guidNo").val();
console.log("lets find the index where the guid is is "+guidVal);
var index = 0;
/*
table.column(6).data().each(function (val,i) {
console.log("the val is:"+val+" the i is:"+i);
var _this = this;
if(val === guidVal) {
console.log("we found it!"+val+" its index is:"+i);
index = i;
var jq = "#"+guidVal;
console.log("js is:"+jq);
table.row(jq).select().scrollTo();
}
});
*/
var jq = "#"+guidVal;
table.row(jq).select().scrollTo();
console.log("we scroll to index:"+index);
});
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.