1. 程式人生 > >DataTable 自定義搜尋條件 _ 自定義查詢引數

DataTable 自定義搜尋條件 _ 自定義查詢引數

var table =$('#orderInfoTable').DataTable({
	processing: true, //載入
    serverSide: true,  //後臺分頁
    searching: false,   //索引
	ajax : {
		url : requestUrl,
		type: "POST",
		dataType: "json",
		data:function(params){   
			params.orderCol = params.columns[params.order[0].column].data;
			params.orderReg = params.order[0].dir;
			var json = $("#form_search").serializeJson();
			$.each(json,function(e){
				params[e] = json[e];
			});
		}
	},
	columns : [ {
		data : "hyHospitalName", 		/* 醫院名稱*/
		orderable:false
	}, {
		data : "propertyTypeName",			/* 屬性型別*/
			orderable:false
	}, {
		data : "propertyValue"		/*屬性值*/
	}, {
		data : "dr"				/*可用狀態(可用狀態 0:禁用,1:可用)*/
	},{
		data : "cdt"				/*訂單建立時間*/
	},{
		data : "mdt"				/*訂單更新時間*/
	},{
		data:null 
	}],
	columnDefs: [
		{
			targets: 2,
			sWidth:'30%',
	        orderable : false,
	        render: function(data,type,row,meta) {
	        	var text = "";
	        	if(row.dataParamType=='boolean' && data=="1"){
	        		return "是";
	        	}else if(row.dataParamType=='boolean' && data=="0"){
	        		return "否";
	        	}else if (row.dataParamType=='textarea'){
	        		var text = data;
	        		if(data.length>100){
	        			var tx = data.substring(0,40).replace(/[\r\n]/g,"")
	        			text = tx + "..." + "<a title='" + data.toString() + "'>[顯示詳情]</a>";
	        		}
		        	return text==null?"":text;
	        	}else{
	        		return data;
	        	}
	        },
	        className: "dt-body-center"
		},
		{
	     	targets: 3,
	        orderable : false,
	        render: function(data, type, row, meta) {
	        	if(data=='1'){
	        		str = "<span class=\"label label-success radius\">啟用</span>";
	        	}else{
	        		str = "<span class=\"label label-default radius\">禁用</span>"
	        	}
	        	return str;
	        },
	        className: "dt-body-center"
	    },
	    {
	    	targets: [4,5],
	    	orderable : true,
	    	render: function(data, type, row, meta) {
		    	if(data==null){
		    		return "";
		    	}
		       	return new Date(data).Format("yyyy-MM-dd hh:mm:ss");
	       },
	       className: "dt-body-center"
	   },
	   {
	      	 targets: 6,
	         orderable : false,
	         render: function(data, type, row, meta) {
	        	 var flag = "";
	        	 var title = "";
	        	 var icron = "";
	        	 if(row.dr == '1'){
	        		 /*flag = "1";*/
	        		 title = "禁用";
	//        		 icron = "&#xe615;"
	        		 icron = "<i id=\"icorn\" class=\"Hui-iconfont\">&#xe631;</i>"
	        	 }
	        	 if(row.dr == '0'){
	        		 /*flag = "0";*/
	        		 title = "啟用";
	//        		 icron = "&#xe631;"
	        		 icron = "<i id=\"icorn\" class=\"Hui-iconfont\">&#xe615;</i>"
	        	 }
	        	 var str = "<td class=\"td-manage\"><a id=\"setStatus\"  onclick=\"enabledDisabledStatus(this,"+row.id+","+row.dr+")\" href=\"javascript:;\" title="+title+" style=\"text-decoration:none\">"+icron+"</a>"
	        		 		+"&nbsp;&nbsp;<a title=\"編輯\" href=\"javascript:;\" onclick=\"edit("+row.id+")\" class=\"ml-5\" style=\"text-decoration:none\"><i class=\"Hui-iconfont\">&#xe6df;</i></a>"
	        		 		+"&nbsp;&nbsp;<a title=\"刪除\" href=\"javascript:;\" onclick=\"del("+row.id+")\" class=\"ml-5\" style=\"text-decoration:none\"><i class=\"Hui-iconfont\">&#xe6e2;</i></a>";
	        	 return str;
	         },
	         className: "dt-body-center"
	     }
	    ],
		scrollY:500,
	    scrollCollapse: true,
	    aaSorting: [[ 4, "desc" ]]
});