Quantcast
Channel: Recent Discussions — DataTables forums
Viewing all articles
Browse latest Browse all 82111

Dynamic Column plus IF statement

$
0
0
I have a datatable which works perfectly.

I am trying it add in an IF statement without any luck.

Part of my current code is this:


function search(field,searchTxt) {
	db.transaction(function (tx) {
		try{
		tx.executeSql("SELECT * FROM books where "+field+" like ?", ['%'+searchTxt+'%'], function (tx, results) {
			var html = [];
			len = results.rows.length;
			for (var i = 0; i < len; i++) {
				var row=results.rows.item(i);
				var a=[];
				a[0]=row.author;
				a[1]=row.title;
				a[2]=row.file;
				html.push( a);
				
			}
			for(i=data.length-1;i>0;--i)
				data.pop();
			
			
			data[0]=html[0];
			try{
			$('#example').html("");
			}catch(e){}

$('#example').dataTable({
        "bJQueryUI": true,
        "sPaginationType": "full_numbers",
        "bDestroy":true,
		"aaData": html,
		"bFilter": false,
		"aoColumns": [
			{ "sTitle": "Author", "sWidth": "33%"  },
			{ "sTitle": "Title", "sWidth": "47%" },
			{
				"bSort": false,
				"sTitle": "Link",
                "sWidth": "20%",
				"sClass": "center",
				"fnRender": function(obj) {
					var sReturn = obj.aData[ obj.iDataColumn ];
					sReturn = '<a href="../book/'+sReturn+'">Get book</a>';
					
					return sReturn;
				}
			}
		]
	} );
		
		});
		}catch(e){
			alert(e);
		}
	});
}


My WEBSQL has 4 cols: title, author, file, ind

What I'd like to do for the last part of my function which creates the link:

				"fnRender": function(obj) {
					var sReturn = obj.aData[ obj.iDataColumn ];
					sReturn = '<a href="../book/'+sReturn+'">Get book</a>';
					
					return sReturn;
				}

Is, in laymans terms say:

If ind = 1 then sReturn = '<a href="../book/'+sReturn+'">Get book</a>';

else

sReturn = '<a href="../book/'+sReturn+'">NEW book</a>';

Where ind is the column value in my WEBSQL

Any help would be most appreciated!

Viewing all articles
Browse latest Browse all 82111

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>