Reputation: 3092
I am populating JQ grid with student details. I have formatted one of the columns to be as hyperlink using a function.
return "<a href='#' onClick='xxx(\"" + rowObject._id + "\")'>"
+ cellvalue + "</a>";
So my grid will contain a column which has a text "abc" (say) formatted as hyperlink. I need to display the value of the selected row in a jquery dialog.
When I try to get the value of this formatted cell using row.link, it gives me the whole anchor tag specifications like
var selrow = jQuery('#studentGrid').jqGrid('getGridParam', 'selrow');
var row = jQuery('#studentGrid').jqGrid('getRowData', selrow);
var link= row['studentInfo.link'];
alert(link);
gives me
<a href="#" onclick="xxx("rowId")">abc</a>
How can I get the value abc alone from the row. Please help.
Upvotes: 1
Views: 2030
Reputation: 73
You can try this if you are using jquery(which is obvious)
var link= row['studentInfo.link'];
link = $(link).html();
console.log(link);
it works for me, it returns the value that it's inside the tag
Upvotes: 0
Reputation: 3456
If you want to get the text inside the a tag, then try this
var link= row['studentInfo.link'].replace(/^.+(?:>)(.+(?=<\/a)).+$/, '$1');
Upvotes: 1
Reputation: 2443
<a href="#" data-value="rowid_here">Text</a>
<script type="text/javascript">
$("a").click(function(){
textval=$(this).text();
alert(textval);
rowid=$(this).data("value");
alert(rowid);
});
</script>
hope this help you
you can also get rowid
Upvotes: 0