how to get a particular cell value from dynamic table using javascript - javascript

I have a table showing records from database. There is a dropdown for selecting a particular user in each row. On change, it should show the corresponding values of the new user.
When I'm selecting a particular user from the dropdown, it should match the col1 and col2 value with the user selected and return col3 value. What I want is to get the col1 and col2 value of that particular row. How can I do it ? Please help me.

You want to use live('click', function(). This will apply on dynamically created elements.
For example, you may try something like;
$('#your_table_id .some_class_in_a_row_to_click').live('click', function(){
$(this).siblings().each(function(){
var column = $(this).find('.some_class_for_column_with_data');
var data = column.text();
alert(data);
});
});
You may apply this on a table having some columns. Clicking on some column with class some_class_in_a_row_to_click will alert text on another column in that row having class some_class_for_column_with_data

Related

Read table cell by javascript

I created table with several columns, one column with textarea field and one with button to save textarea value.
First thing I want to read textarea field. I use this code
<script>
$(document).ready(function(){
// code to read selected table row cell data (values).
$("#myTable").on('click','.btnSelect',function(){
// get the current row
var currentRow=$(this).closest("tr");
var colT=currentRow.find("td:eq(7)").text(); // OR
var colTa=currentRow.find("textarea").text();
alert(colT + colTa);
});
});
</script>
Anyway I receive the original value from table, but I need new or updated value.

Get HTML element by JavaScript

How can I reach the first row and the first column (using javaScript) from a table in specific URL?
for example in the following URL:
https://www.w3schools.com/jsref/dom_obj_table.asp
In 'Table Object Methods', I want to get "createCaption()" .
Thanks!
you can try this...
you get value into rows of table HTML.
var row = document.getElementById("myTable").rows[0].innerHTML;
Using css you can do
var elem = element.all(by.css('table tr:nth-child(2) td:nth-child(1)').last();
This selects the first column from the second row that is in a table.
Using element.all because there are 3 tables it could apply to, which is why you need the .last() because the table you wanted referenced was the last table. Would work better if the table has an unique ID to reference it with.

SlickGrid_AppendNew Row with different Id

I m using slickgrid V2.2, I am trying to append new row from the selected row along with data in the selected row. Its working fine, but in the added row the same id generating as the selected row by default. I am using below code. Kindly help me out to append a new row with different id from selectedrow
var row = grid.getDataItem(selectedRow);
dataView.addItem(row);
grid.render();
grid.setSelectedRows([]);
row is simply an object containing the columns, so row.id = {new id}; should work. You'll need to generate the id somehow depending on how your scheme works (don't use the curly brackets around the new id value, I'm just indicating that this value needs to be inserted).

How to retrieve column data from Footable

We have a Footable in our page with some data, and one column has a delete row button, working as expected.
Problem is, when deleterow is pressed, we want to retrieve from the column a value, to do some process with it.
Example:
ID -- Name -- Delete
--------------------
01 -- John -- Delete
02 -- Doe -- Delete
When I press delete on second row, I want to retrieve this value, to search on an array, and delete it from there too, and to pass as parameter to an Ajax call.
I readed something like data-value but don't know how to get it. On delete row, there is a code like this:
$('table').footable().on('click', '.row-delete', function(e) {
e.preventDefault();
//get the footable object
var footable = $('table').data('footable');
//get the row we are wanting to delete
var row = $(this).parents('tr:first');
//delete the row
footable.removeRow(row);
});
I know row has the data, but don't know/understand how to extract the column I need.
Regards and thanks.
You can get at the columns in the TR as TD elements
eg
var columns = $('td',row); // all the TD elements in the row
You can get at individual columns by index (0-based) eg
var someColumn = $('td',row)[1];
Or if the column you are intersted in has a class eg:
var someColumn = $('td.someclass',row);

how to add value to a particular column and row in a gridView in javascript?

I am trying to add a value to a gridView column on a specific row via Javascript. Previously I have done this via .NET.
But now I want to try this alternative:-
document.getElementById('<%=GridView1.ClientID%%>').rows[1].cells[1].value = IDentification#;
This is obviously not the correct syntax. Any ideas?
It should be innerHTML not value
document.getElementById('<%=GridView1.ClientID%>')
.rows[1]
.cells[1]
.innerHTML= yourvariable; //or "astring"
This will insert the text in your variable to 2nd row's 2nd column of the table rendered by the gridview.

Categories

Resources