How to reload datatable onchange function in select tag using ajax

How to reload datatable onchange function in select tag using ajax

sabusabu Posts: 10Questions: 3Answers: 1
edited January 2016 in Free community support
<div class="ibox-content">
                    <div class="row top-content">
                        <div class="col-md-offset-5">
                            <label class="col-sm-3 control-label filter-label">State</label>
                            <div class="col-sm-3">
                                <select class="form-control state" name="account" onchange="init()"  id="searchstring">
                                    <option value="0">Select State</option>
                                    <c:forEach var="state" items="${stateList }">
                                        <option value="${state.stateId}" id="searchstring">${state.stateName}</option>
                                    </c:forEach>
                                </select>
                            </div>
                        </div>


                    </div>
                    <table id="example"
                        class="table table-striped table-bordered table-hover"
                        cellspacing="0" width="100%">
                        <thead>
                            <tr>
                                <th>S.no</th>
                                <th></th>
                                <th>Country</th>
                                <th>State</th>
                                <th>District</th>



                            </tr>
                        </thead>
                        <tbody>
                            <c:forEach var="district" items="${districtList}"
                                varStatus="status">
                                <tr id="info">
                                    <td>${status.index + 1}</td>
                                    <td class="text-center"><a class="edit_color"
                                        href="DistrictEdit?districtId=${district.districtId}"> <span
                                            class="glyphicon glyphicon-pencil"></span>
                                    </a> <a class="delete_color demo4"
                                        href="DistrictDelete?countryId=${district.districtId }"> <span
                                            class="glyphicon glyphicon-trash"></span></a></td>
                                    <td>${district.getStateCommon().getCountryCommon().getCountryName()}</td>
                                    <td>${district.getStateCommon().getStateName()}</td>
                                    <td>${district.districtName}</td>
                                </tr>

                            </c:forEach>


                        </tbody>
                    </table>
                </div>

================================Controller=============================

@RequestMapping(value = "/StateSelect", method = RequestMethod.GET)
@ResponseBody
public List<District> StateSelect(String search) {
/* int s = Integer.parseInt(request.getParameter("search"));
System.out.println("=================================="+s);
List<District> listdistrict = abstractHandler.idBasedSearch(s);
System.out.println("District values============="+listdistrict.get(0));
System.out.println("BEFORE SEARCH==========");
return listdistrict;*/
System.out.println("Testing-------------"+search);
List<District> listdistrict = abstractHandler.idBasedSearch(search);
System.out.println("District values============="+listdistrict.get(0).getDistrictName());
return listdistrict;

}

I m using Spring mvc with hibernate .
I m confused with how to reload tha data with response data.
how to solve this problem

Answers

  • glendersonglenderson Posts: 231Questions: 11Answers: 29

    Since you don't appear to be using ajax, it's a bit difficult to explain. But, if you set up dataTables to use ajax, your ajax page needs to read your database and then format the data into JSON format. You want no HTML headers at all. You also want to set up the , columns: feature in datatables to match your JSON data.

This discussion has been closed.