how to retrieve data from database in datatable on click event
how to retrieve data from database in datatable on click event
I am new in json and jquery...i used jquery plugin for datatable and i created dropdownlist for select today,week and month data from database and want to display in datatable,m getting data in json format (in browser with plain json format) but unable to display it in datatable. I tried below code in jsp:
in servlet : (call java method from DAO class)
List<Trans> listOfdata = null;
DataTable dataTable = new DataTables();
response.setContentType("application/json");
String temp = (String) request.getParameter("days");
System.out.println(temp);
switch(temp)
{
case "D" :
listOfdata = String temp = (String) request.getParameter("days");
switch(temp)
{
case "D" :
listOfdata = DAO.getAllData();
break;
case "W" :
listOfdata = DAO.getWeeklyData(temp);
break;
case "M" :
listOfdata = DAO.getMonthlyData(temp);
break;
default :
listOfdata = DAO.getAllData();
break;
}
dataTable.setAaData(listOfdata);
Gson gson = new GsonBuilder().setPrettyPrinting().create();
String json = gson.toJson(dataTable);
response.getWriter().print(json);
in javascript :
$(document).ready(function() {
$(".DataTable").dataTable({
"sPaginationType" : "full_numbers",
"bProcessing" : false,
"bServerSide" : false,
"sAjaxSource" : "displayData",
"bJQueryUI" : true,
"aoColumns" : [
{ "mData": "datetime" },
{ "mData": "t_no" },
{ "mData": "m_t_id" },
{ "mData": "t_type" },
{ "mData": "t_amt" },
{ "mData": "t_status" },
{ "mData": "t_action" }
]
} );
} );