Я получаю некоторые данные и показываю в таблице.Здесь я использую таблицу данных.Все работает нормально, но не в состоянии сортировать данные, щелкнув заголовок столбца таблицы данных.Я не могу понять, в чем проблема.Пожалуйста, помогите мне найти решение.Мой HTML, Javascript и серверный код написаны ниже:
<div class="widget-body no-padding table-responsive">
<table id="manage_quote" class="table table-striped table-bordered table-hover" width="100%">
<thead>
<tr>
<th data-hide="phone">Id</th>
<th data-class="expand"><i class="fa fa-fw fa-user text-muted hidden-md hidden-sm hidden-xs"></i>User Name</th>
<th data-class="expand"><i class="fa fa-fw fa-user text-muted hidden-md hidden-sm hidden-xs"></i> Agent Name</th>
<th data-hide="phone,tablet"><i class="fa fa-fw fa-calendar txt-color-blue hidden-md hidden-sm hidden-xs"></i> Created On</th>
<th data-hide="phone,tablet">Status</th>
<th data-hide="phone,tablet">Action</th>
</tr>
</thead>
</table>
</div>
Javascript
<script>
$( document ).ready(function() {
var table = $('#manage_quote').dataTable({
"bServerSide": true,
"sAjaxSource": "/common/getDetails",
"bProcessing": true,
"bSort": true,
"pageLength" : 10,
language: {
paginate: {
next: '→', // or 'â'
previous: '←' // or 'â'
}
}
});
});
</script>
Spring Controller Class
@RequestMapping(value="/common/getDetails")
public void manageAdvisorDetails(HttpServletRequest request, HttpServletResponse response)
{
try
{
HashMap<String, String> userMap = (HashMap<String, String>) request.getSession().getAttribute("userMap");
if(userMap != null && userMap.get("user_type").equalsIgnoreCase(Utils.ADMIN))
{
System.out.println("calling");
String sEcho = request.getParameter("sEcho");
String sSearch = request.getParameter("sSearch");
String sColumns = request.getParameter("sColumns");
String iDisplayStart = request.getParameter("iDisplayStart");
String iDisplayLength = request.getParameter("iDisplayLength");
String iColumns = request.getParameter("iColumns");
String iTotalRecords = "";
String iTotalDisplayRecords = "";
JsonArray data = new JsonArray();
ManageDetails manageUsersResponse = commonDAO.getDetails( sSearch, iDisplayStart, iDisplayLength);
iTotalRecords = manageUsersResponse.getNoOfTotalRecords();
iTotalDisplayRecords = manageUsersResponse.getNoOfRecords();
List<Quote> quoteList = manageUsersResponse.getQuoteList();
for (Quote quote : quoteList)
{
System.out.println(quote.getId());
System.out.println(quote.getFirst_name());
System.out.println(quote.getLast_name());
System.out.println(quote.getAgent_name());
JsonArray row = new JsonArray();
row.add(new JsonPrimitive(quote.getId()));
row.add(new JsonPrimitive(quote.getFirst_name() + " " + quote.getLast_name()));
row.add(new JsonPrimitive(quote.getAgent_name()));
row.add(new JsonPrimitive(quote.getQuote_date().toString()));
if(quote.getPayment_status().equalsIgnoreCase(Utils.PAYMENT_COMPLETE))
{
String html = "<a href='/admin?id=" + quote.getId() + "' ><span class='text-success' aria-hidden='true'>" + quote.getPayment_status() + "</span></a>";
row.add(html);
}
else
{
String html = "<a href='/admin?id=" + quote.getId() + "' ><span class='text-info' aria-hidden='true'>" + quote.getPayment_status() + "</span></a>";
row.add(html);
}
row.add(new JsonPrimitive("<a href='/admin/getClientDetails?id=" + quote.getId() + "'><span class='btn btn-xs btn-success'>View</span></a>"));
data.add(row);
}
Gson gson = new Gson();
JsonObject jsonResponse = new JsonObject();
jsonResponse.addProperty("sEcho", sEcho);
jsonResponse.addProperty("iTotalRecords", iTotalRecords);
jsonResponse.addProperty("iTotalDisplayRecords", iTotalDisplayRecords);
jsonResponse.add("aaData", gson.toJsonTree(data));
response.setContentType("application/Json");
response.getWriter().print(jsonResponse.toString());
}
else
{
}
}
catch (Exception ex)
{
ex.printStackTrace();
}
}
Пружина DAO Класс
public static ManageDetails getQuotes(String searchTerm,String iDisplayStart, String iDisplayLength)
{
Session session = null;
ManageDetails ManageDetails = null;
UserDetails userdetails = null;
List<UserDetails> quoteList = null;
try
{
ManageDetails = new ManageDetails();
session = HibernateUtils.getSession();
session.getTransaction().begin();
String query_noOfTotalRecords = "select count(*) from UserDetails";
String query_str = "from UserDetails ";
int noOfRecordsPerPage = Integer.parseInt(iDisplayLength);
int startIndex = Integer.parseInt(iDisplayStart);
int endIndex = startIndex + noOfRecordsPerPage;
if (searchTerm !=null && !searchTerm.equalsIgnoreCase("")){
query_str+=" where (id like '%"+searchTerm+"%'";
query_str+=" or first_name like '%"+searchTerm+"%'";
query_str+=" or last_name like '%"+searchTerm+"%'";
query_str+=" or agent_name like '%"+searchTerm+"%'";
query_str+=" or title like '%"+searchTerm+"%')";
}
query_str+=" order by id desc";
Query query = session.createQuery(query_str);
query.setFirstResult(startIndex);
query.setMaxResults(noOfRecordsPerPage);
Integer noOfRecords = ((Long)session.createQuery("select count(*) " + query_str).uniqueResult()).intValue();
quoteList = query.getResultList();
int noOfPages = noOfRecords / 20;
int reminderRecords = noOfRecords%20;
if(noOfPages == 0)
{
noOfPages = 1;
}
if(reminderRecords > 0 && noOfRecords > 20)
{
noOfPages++;
}
ManageDetails.setQuoteList(quoteList);
ManageDetails.setNoOfPages(String.valueOf(noOfPages));
ManageDetails.setNoOfRecords(String.valueOf(noOfRecords));
ManageDetails.setPageId(String.valueOf(""));
ManageDetails.setNoOfTotalRecords(String.valueOf(session.createQuery(query_noOfTotalRecords).uniqueResult()));
session.getTransaction().commit();
}
catch(Exception ex)
{
session.getTransaction().rollback();
ex.printStackTrace();
}
return ManageDetails;
}