Click here to Skip to main content
15,908,445 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have one data table,on loading of data table i need to show some images based on some values in one column..and at the same time onclick of that column i need to change that image..it's like falg an dimportant columns in our gmail..At present iam able to show images based on some conditions using "render: getStarredflag,".But on that same column i need to give hyperlink also on click of which we need to update db and change the image.

This is what i have tried,sample code.How to give hyperlink and call test() function onclick of that image column.??


What I have tried:

JavaScript
<pre>Getmaildetailstable = $('#Getmaildetailstable').DataTable({
                 columnDefs: [{
                     orderable: false,
                     className: 'select-checkbox',
                     defaultContent: "",
                     targets: 0,
					 visible: false
                 }, {
                     data: "image",render: getStarredflag,
                     defaultContent: "",
                     targets: 6,
                    visible: true
                 }
                 order: [
                     [2, 'asc']
                 ],
                 "searching": false,
                 "lengthChange": true
             });
			 
			 function getStarredflag(data, type, full, meta) {
            var starflag=full.STARRED_FLAG; 
			if(starflag=="1")
			{
			return '<img src="wcp/theme/default/icon/action/star_icon1.png" />';
			}
			else if(starflag=="0")
			{
			return '<img src="wcp/theme/default/icon/action/star_yellow.png" />';
			}
          }
		  function test()
		  {
			  alert("test");
		  }
Posted
Updated 9-Feb-18 4:18am
Comments
Murali Gowda 7-Feb-18 8:01am    
Attache a click event to the img tag, that should make the things work.
Member 12504833 7-Feb-18 8:03am    
iam giving hyperlink like this,but onclick itself is not clickable,means iam not getting correct way to cal function,,because it is not only giving hyperlink also first calling one function,getting image and then giving hyper link.
data: "image",render: getStarredflag,function ( data, type, row ) {
return '' + data + '';
Murali Gowda 7-Feb-18 8:07am    
You have code like this
if(starflag=="1"){
return '<img src="wcp/theme/default/icon/action/star_icon1.png" />';
}

change it like this
if(starflag=="1"){
return '<img src="wcp/theme/default/icon/action/star_icon1.png" onclick="test()" />';
}
Richard Deeming 8-Feb-18 12:22pm    
You should post this as a solution. :)
Murali Gowda 9-Feb-18 10:15am    
Sure, will do it now. Thansk you :)

1 solution

You have code like this
JavaScript
if(starflag=="1"){
return '<img src="wcp/theme/default/icon/action/star_icon1.png" />';
}

change it like this
JavaScript
if(starflag=="1"){
return '<img src="wcp/theme/default/icon/action/star_icon1.png" onclick="test()" />';
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900