How to get the selected row id in javascript? - javascript

I'm trying to use the following JavaScript function to get a particular cell value from a jqgrid upon click.
In the below function #datagrid is the table where the jqgrid is stored in.
$("#datagrid").click(function(){
var selr = $("#datagrid").getCol('companyid');
alert(selr);
});
My problem is when I click the jqgrid it will show ALL row id's from the jqgrid in the alert message, but I only need a particular companyid which was selected from the jqgrid. How do I make this work?

You should use getCell function to read the value from the cell identified by row id.
So, You should try something like this:
$("#datagrid").click(function(){
var grid = jQuery('#datagrid');
var sel_id = grid.jqGrid('getGridParam', 'selrow');
var myCellData = grid.jqGrid('getCell', sel_id, 'MyColName');
});

Related

How to detect select onChange in a row cell

I am creating a dynamic table using java script and jquery, one of my project requirement is a select box in a row cell,
From the this SO link i am able to place a on click listener on a table row which gives me id of table row and cell(tr and td) but i am not able to detect select onchange i have also tried "jQuery get value of select onChange" but it is also not working in my case!!
My problem is
How to detect select on Change in a row cell as i have to update that
changed data in database?
thanks in advance!!!!!
I believe this will get everything you'll need for your database (value selected, cell and row it was selected in)... something like:
JSFiddle
$("td select").on("change", function() {
var value = this.value;
var $cell = $(this).parent();
var $row = $cell.parent();
alert("Selected ["+value+"] in cell ["+$cell.index()+"] of row ["+$row.index()+"]");
});
$(document).on('change','td',function(){
//Do your abacadabra!
});

Put previos data in table rows

I've table with with 3 column with the following name
name <----input field - first column
user <----CheckBox -second column
address<----CheckBoxv-third column
I've in the table in-line create and if user click on edit for specific row and
change the name /user/address and instead of save do cancel I want to restore the previos data,I was able to do this for the input property but not sure how to do it for the checkBoxes,any idea how?
This is how I restore the data for the name property
var $firstCell = $row.find("td:first"),
checkBox = $row.find("input[type=checkbox]"),
....
$firstCell.text(previousData.name);
In the previosData I store all the data when the user just click on edit
I think what you might be looking for is something like this:
var $checkboxUser = $row.find('input[name=user]'),
$checkboxAddress = $row.find('input[name=address]');
previousData.statusUserCheckbox = $checkboxUser.prop('checked');
previousData.statusAddressCheckbox = $checkboxAddress.prop('checked');
// ...
$checkboxUser.prop('checked', previousData.statusUserCheckbox);
$checkboxAddress.prop('checked', previousData.statusAddressCheckbox);
http://api.jquery.com/prop/

Get the cell value in jqgrid

How to get the particular jqgrid cell value using java script?For example the jqgrid having four columns like id,name,subject1,subject2.now I click the particular row and I need to get the id.how to achieve this?I use the onSelectRow in jqgrid I get the solution but I need to get the javascript?
I use the Jqgrid onSelectRow
onSelectRow: function(id){
var rowData = jQuery(this).getRowData(id);
var temp= rowData['name'];
alert(temp);
}
As #ClydeFlog showed in the example, try this:
var Id = jQuery('#gridName').jqGrid('getGridParam','selrow');
See the result below in the console:
Page example on the 'Get Selected Rows' button click.

Jqgrid multiselect selected rows count?

I'm using Jqgrid by multiselect option. I want to get selected rows count on Jqgrid .
I tried that but no luck...
var count = jQuery('#grid').length;
if (count > 5)
alert('The Selected Rows More Than 5')
You should just get the length of the array selarrrow:
var selRowIds = jQuery('#grid').jqGrid('getGridParam', 'selarrrow');
alert ('The number of selected rows: ' + selRowIds.length);
This works for me: Place a link anywhere you want
Click me!
and now simply register the callback function
$("#displayNoSelectedRows").click(function() {
var no = $("input[id^='jqg_gridid_']:checked").length;
alert(no);
return false;
});
for this link, where gridid is the table's id. With the knowledge of how the checkboxes are named (or better the way the ids are assigned) this is a possible way to get the number of selected checkboxes.

YUI get specific cell value when selecting a row to fire event

I am using Yahoo UI library, in particular this example.
What I want is to get a particular column's value when clicking (selecting) a row.
I am using this code:
var makis = function() {alert("blabla"); };
myDataTable.subscribe("rowClickEvent", makis);
and works, but I just don't know how to get a column's value in the particular row.
Ok i found it on my own, i am posting if anyone has the same problem.
myDataTable.subscribe("rowClickEvent", function(oArgs) {
var elTarget = oArgs.target;
var oRec = this.getRecord(elTarget);
console.log("value:" + oRec.getData("column_we_want"));
}

Categories