Jsgrid: JS GRID on Dynamic data

Created on 28 Mar 2017  路  6Comments  路  Source: tabalinas/jsgrid

HELLO,I HAVE FETCHED THE DATA FROM DATABASE USING JAVA AND STORES IT ON JSON ARRAY .NOW I WANT SHOW THE DATA ON JSGRID TABLE PLEASE HELP ON THIS PROBLEM.
THIS IS MY JSGRID CODE

 $("#jsGrid").jsGrid({
         height: "70%",
         width: "100%",
         filtering: true,
    editing: true,
    paging: true,
    pageSize: 15,
    pageButtonCount: 5,
       fields: [
    { name: "Patient ID", type: "text", width: 150 },
    { name: "PatientName", type: "text", width: 150 },
    { name: "visitID", type: "text", width: 150 },
    { name: "Contact no", type: "text", width: 200 },
    { type: "kk" }
    ]
    });
    </script>
THIS IS MY BACKEND CODE
            ResultSet rs = st.executeQuery(query);


            while (rs.next()) {

                  JsonArray row = new JsonArray();
                 row.add(new JsonPrimitive(rs.getString("temp_patient_id")));
                    row.add(new JsonPrimitive(rs.getString("temp_patient_name")));
                    row.add(new JsonPrimitive(rs.getString("temp_gender_id")));
                    row.add(new JsonPrimitive(rs.getString("temp_mobile")));
                    data.add(row);
            }
            jsonResponse.add("ResponseData", data);
                out.println(jsonResponse);
help wanted

All 6 comments

Yes,
I am also having the same problem.
In 1st step we convert Resultset data into Json Object.
can any one explain How we load Json object data into Js grid.

Per the documentation, you need to provide a data property or controller object to JSGrid

Firstly, Thank you for your response.
controller: {
loadData: function (filter) {
return $.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
url: "/project-name/filename",
data: filter,
dataType: "json"
});
}},
i kept like this but it it is not working properly ,please tell me appropriate solution clearly.
Thanks in Advance

Hi Venkatramanaryams,

The data returned by your ajax call should either be in this format:

[{"Author":"Gambardella, Matthew","Description":"An in-depth look at creating applications with XML.","Genre":"Computer","ID":"bk101","PlotNo":"101","Price":44.95,"Title":"XML Developer's Guide"},{"Author":"Ralls, Kim","Description":"A former architect battles corporate zombies,\u000a an evil sorceress, and her own childhood to become queen\u000a of the world.","Genre":"Fantasy","ID":"bk102","PlotNo":"102","Price":5.95,"Title":"Midnight Rain"}]

If there are any changes in the structure of the data returned by your ajax call, you can form it as object array as shown above on success of the ajax call.

Thanks tanhargithub,
Is that ajax call is wrong?
it is written like that only

thank you i got the grid @tanhargithub @richraid21 @tabalinas

Was this page helpful?
0 / 5 - 0 ratings

Related issues

andymacourek picture andymacourek  路  3Comments

fredericoregateiro picture fredericoregateiro  路  3Comments

comiscienceknight picture comiscienceknight  路  3Comments

samuelrobertson picture samuelrobertson  路  3Comments

jufei picture jufei  路  3Comments