jQuery select Select row based on another table row index
I have 2 tables. One holds only first column of my "data table" rest is stored in another table, that is placed right to first.
What I need to do is to get all the data from specific row to pass it to jqplot.
My tables look like this: http://jsfiddle.net/Misiu/eajpy/1/this
. My code basically works, but I think it can be improved. Any advice will be helpful :)
My code looks like this:
EDIT I'm I'm using this code in ASP page, so that every time I use UpdatePanel I must call my functions again.
I haven't added @Arne great code yet, but I'll do it as fast as possible and update my question again for future advice's :)
jQuery select row based on another table row index
I have 2 tables. One holds only first column of my "data table" rest is stored in another table, that is placed right to first.
What I need to do is to get all the data from specific row to pass it to jqplot.
My tables look like this: http://jsfiddle.net/Misiu/eajpy/1/
My code basically works, but I think it can be improved. Any advice will be helpful :)
My code looks like this:
EDIT I'm using this code in ASP page, so that every time I use UpdatePanel I must call my functions again.
I haven't added @Arne great code yet, but I'll do it as fast as possible and update my question again for future advice's :)
Select row based on another table row index
I have 2 tables. One holds only first column of my "data table" rest is stored in another table, that is placed right to first. What I need to do is to get all the data from specific row to pass it to jqplot.
My tables look like this . My code basically works, but I think it can be improved.
I'm using this code in ASP page, so that every time I use UpdatePanel I must call my functions again.
EDIT I'm using this code in ASP page, so that every time I use UpdatePanel I must call my functions again.
This is my plot function:
function plot() {
var $plot;
var dataTableRows = $('#Grid3_br tbody tr');
$('td.akcje').on('click', function() {
var $newTitle = $(this).next().text();
var myData = [],
element = $(this),
rowIndex = element.parent().index();
$(dataTableRows[rowIndex]).map(function() {
return $(this.cells).get();
}).each(function(index, value) {
myData.push(['M' + index, parseFloat($(this).html())]);
})
$('#wykres1').empty();//clears old plot. Don't know why re-plotting don't work for me
$plot = $.jqplot('wykres1', [myData], {
title: $newTitle,
axes: {
xaxis: {
renderer: $.jqplot.CategoryAxisRenderer,
tickOptions: {
formatString: '%s'
}
},
yaxis: {
tickOptions: {
formatString: '%.2f zł'
}
}
},
highlighter: {
show: true,
sizeAdjust: 7.5,
tooltipAxes: 'y'
},
cursor: {
show: false
}
});
$(window).resize(function() {
$plot.replot({
resetAxes: true
});
});
});
}
I haven't added @Arne great code yet, but I'll do it as fast as possible and update my question again for future advice's :)
EDIT I'm using this code in ASP page, so that every time I use UpdatePanel I must call my functions again.
This is my plot function:
function plot() {
var $plot;
var dataTableRows = $('#Grid3_br tbody tr');
$('td.akcje').on('click', function() {
var $newTitle = $(this).next().text();
var myData = [],
element = $(this),
rowIndex = element.parent().index();
$(dataTableRows[rowIndex]).map(function() {
return $(this.cells).get();
}).each(function(index, value) {
myData.push(['M' + index, parseFloat($(this).html())]);
})
$('#wykres1').empty();//clears old plot. Don't know why re-plotting don't work for me
$plot = $.jqplot('wykres1', [myData], {
title: $newTitle,
axes: {
xaxis: {
renderer: $.jqplot.CategoryAxisRenderer,
tickOptions: {
formatString: '%s'
}
},
yaxis: {
tickOptions: {
formatString: '%.2f zł'
}
}
},
highlighter: {
show: true,
sizeAdjust: 7.5,
tooltipAxes: 'y'
},
cursor: {
show: false
}
});
$(window).resize(function() {
$plot.replot({
resetAxes: true
});
});
});
}
I haven't added @Arne great code yet, but I'll do it as fast as possible and update my question again for future advice's :)
I have 2 tables. One holds only first column of my "data table" rest is stored in another table, that is placed right to first.
What I need to do is to get all the data from specific row to pass it to jqplot.
My tables look like this: http://jsfiddle.net/Misiu/eajpy/1/
My code basically works, but I think it can be improved. Any advice will be helpful :)
My code looks like this:
$('table#baseTable > tbody > tr > td''td').click(function() {
var rowIndex = $(this).parent().index();
$('div#log').html(rowIndex);
var myData = [];
$('#dataTable tbody tr:eq(' + rowIndex + ')').map(function() {
return $(this.cells).get();
}).each(function() {
var headerVal = $(this).closest("table").find("thead > tr > th").eq($(this).index()).html();
myData.push([headerVal, $(this).html()]);
})
alert(myData);
console.log(myData);
});
I have 2 tables. One holds only first column of my "data table" rest is stored in another table, that is placed right to first.
What I need to do is to get all the data from specific row to pass it to jqplot.
My tables look like this: http://jsfiddle.net/Misiu/eajpy/1/
My code basically works, but I think it can be improved. Any advice will be helpful :)
My code looks like this:
$('table#baseTable > tbody > tr > td'').click(function() {
var rowIndex = $(this).parent().index();
$('div#log').html(rowIndex);
var myData = [];
$('#dataTable tbody tr:eq(' + rowIndex + ')').map(function() {
return $(this.cells).get();
}).each(function() {
var headerVal = $(this).closest("table").find("thead > tr > th").eq($(this).index()).html();
myData.push([headerVal, $(this).html()]);
})
alert(myData);
console.log(myData);
});
I have 2 tables. One holds only first column of my "data table" rest is stored in another table, that is placed right to first.
What I need to do is to get all the data from specific row to pass it to jqplot.
My tables look like this: http://jsfiddle.net/Misiu/eajpy/1/
My code basically works, but I think it can be improved. Any advice will be helpful :)
My code looks like this:
$('table#baseTable > tbody > tr > td').click(function() {
var rowIndex = $(this).parent().index();
$('div#log').html(rowIndex);
var myData = [];
$('#dataTable tbody tr:eq(' + rowIndex + ')').map(function() {
return $(this.cells).get();
}).each(function() {
var headerVal = $(this).closest("table").find("thead > tr > th").eq($(this).index()).html();
myData.push([headerVal, $(this).html()]);
})
alert(myData);
console.log(myData);
});