这是上一篇的内容http://blog.csdn.net/u012743772/article/details/50517769
<script type="text/javascript"> var inTable; $(document).ready(function(){ inTable = $('#inTable').DataTable( { scrollX: true, aoColumns : [ { mData : 'col1' , sTitle : '<s:text name="*.*.table.label.*"/>'}, { mData : 'col2' , sTitle : '<s:text name="*.*.table.label.*"/>'}, { mData : 'col3' , sTitle : '<s:text name="*.*.table.label.*"/>'}, { mData : 'col4' , sTitle : '<s:text name="*.*.table.label.*"/>'}, { mData : 'col5' , sTitle : '<s:text name="*.*.table.label.*"/>'}, { mData : 'col6' , sTitle : '<s:text name="*.*.table.label.*"/>'}, { mData : 'col7' , sTitle : '<s:text name="*.*.table.label.*"/>'} ], ajax: { url: "*.search.action", type: "POST", data : buildSearchCriteria }, order: [0, 'desc'], dom: "t" +"<'row'<'col-xs-4'l><'col-xs-7'i><'col-xs-8'p>>", }); $('#inTable tbody').on( 'click', 'tr', function () { inTable.$('tr.selected').removeClass('selected'); $(this).addClass('selected'); $("#invoiceId").val($('td', inTable.$('tr.selected')).eq(0).text()); alert( $("#invoiceId").val()); } ); $('#invoicesSearch').click( function () { $('#codeThirdInvoiced').removeClass('has-error'); if (validate()) { alert("success"); inTable.ajax.reload(); } }); });
function buildSearchCriteria(search) { search['search.country'] = $("#countryCode").val(); search['search.code'] = $("#code").val(); search['search.name'] = $("#name").val(); search['search.consoliNumber'] = $("#consoliNumber").val(); search['search.subInvoice'] = $("#subInvoice").val(); return search; }
<table id="inTable" class="table table-bordered" cellspacing="0" width="100%"></table>
public class InAction extends **Action { /** The Constant serialVersionUID. */ private static final long serialVersionUID = -5328176248429318628L; @Autowired private SearchInScreenDto search; @Inject private InvoiceServiceGui invoiceServiceGui; @Override public String input() { return INPUT; } public void searchInvoice() throws IOException { HttpServletResponse response = ServletActionContext.getResponse(); response.setContentType("text/html;charset=utf-8"); List<InScreenDto> listDto = invoiceServiceGui.searchInvoiceByParam(search); String jsonResults = loadInvoiceTableDataJSON(listDto); PrintWriter out = response.getWriter(); out.println(jsonResults); } private String loadInvoiceTableDataJSON(List<InScreenDto> list) { JSONObject obj = new JSONObject(); JSONArray lineItemArray = new JSONArray(); JSONObject jsonObj = null; for (InScreenDto dto : list) { jsonObj = new JSONObject(); jsonObj.put("col1", dto.get**()); jsonObj.put("col2", dto.get**()); jsonObj.put("col3", dto.get**()); jsonObj.put("col4", dto.get**()); jsonObj.put("col5", dto.get**()); lineItemArray.add(jsonObj); } obj.put("aaData", lineItemArray); return obj.toString(); } }