jQWidgets Forums

jQuery UI Widgets Forums Grid Accessing jqxgrid data in controller

This topic contains 7 replies, has 5 voices, and was last updated by  Akshatha Raju 12 years ago.

Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
  • Accessing jqxgrid data in controller #18380

    Akshatha Raju
    Participant

    I am using Keyboard navigation Jqxgrid. I am able to bind the grid by passing data from the controller file using JAVA. But now i want to fetch the data displayed in jqxgrid and access it in controller, to insert the data in the database using POST method. How can I achieve this? Thanks in advance.

    Accessing jqxgrid data in controller #18384

    Peter Stoev
    Keymaster

    Hi Akshatha Raju,

    For CRUD operations, please take a look at: http://www.jqwidgets.com/jquery-widgets-demo/demos/jqxgrid/createremoveupdatedata.htm.

    The ‘addrow’, ‘deleterow’ and ‘updaterow’ callback functions are called when a row is added, deleted or updated. In these functions, you can make Ajax calls to your server by using the jQuery’s Ajax functions. The callback functions are called by the jQuery Grid with parameters like: row’s id, row’s data and commit. If the synchronization with your server is successful, call commit(true) to confirm the changes in the Grid or commit(false) to cancel them.

    Best Regards,
    Peter Stoev

    jQWidgets Team
    http://www.jqwidgets.com

    Accessing jqxgrid data in controller #18414

    Akshatha Raju
    Participant

    Hi Peter,
    Thanks for the reply! The explanation which you have given above is for manipulating a single row at a time (update or delete), but what I actually want is to fetch the data which is displaying in the jqxgrid, may be in some JSON format and to insert it into the database. What I mean is on click of some button, the data displaying in jqxgrid is to be inserted into the database. Is there any solution for this sort of requirement?

    Accessing jqxgrid data in controller #18431

    Keshavan
    Participant

    Hi,

    may be of some help, use an array of rowid and rowdata to update more than 1 row, seems there is some help w.r.t this in API.

    Thanks,

    Keshavan

    Accessing jqxgrid data in controller #20983

    rcm01
    Participant

    Hello AR; If you are still having the issue and I understand what you want to do, I did this with a jscript function that passes a json object to the controller. I call the function from a button I labled “Process Grid” on the htlm page. In the function I create an object that contains several properties including one that is called “rows”. I create rows by calling $(“#myGrid”).jqxGrid(‘getrows’). After the object is built I call JSON.stringify(myTransferObject) to create a JSON variable to pass to the controller.

    This is some pseudo code (a.k.a. not tested) to give you an example of the parts.

    function processGrid()
    {
    var parentPrimaryKey = document.getElementById('ParentPrimaryKey').vlaue;
    var rows = $("#myGrid").jqxGrid('getrows');
    var myTransferObject = {
    ParentPrimaryKey: parentPrimaryKey
    , Rows: rows
    }
    var myTransferObjectJson = JSON.stringify(myTransferObject);
    $.ajax({
    url: "myContrller/addrows"
    , type: post
    , dataType: "json"
    , data: myTransferObjectJson
    , contentType: "application/json; charset=utf-8"
    , success: function(data){ doSuccess(); }
    , error: function(data){ doError(); }
    }
    Accessing jqxgrid data in controller #21126

    Akshatha Raju
    Participant

    Hi rcm01, Thank you so very much for the solution. I am now able to get the json data in controller. But now my worry is i need to insert every row present in this JSON data into database. So, are you aware of any JSON parser or so to convert this json data into maybe a LIST, a list of DTO which will hold the data as individual rows, so that i can easily insert into the database, by iterating through the rows of List. Any help would be appreciated. Thanks in advance!

    Accessing jqxgrid data in controller #21132

    Klaus H
    Participant

    Hello Akshatha Raju,

    I have used the Grid in an example to get all the Data from the grid, put it in one JSON object and transfer all the data in one request to the server. It’s all the same, you just use the JSON.stringify on an array. Here is how I did that.

    var rows = $('#jqxGrid').jqxGrid('getrows');
    $.ajax({
    url: "YourURL",
    cache: false,
    type: "POST",
    contentType: "application/json; charset=utf-8",
    async: false,
    dataType: "json",
    data: JSON.stringify(rows)
    }).done(function( data )
    {
    //your code here
    }).fail(function(){alert("fail");});

    And in JAVA on the server side, you can read the String with request.getReader() via a String Buffer and then build a JSONArray object from that string and then process the data. I hope that helped and I understood your problem. 😉

    Accessing jqxgrid data in controller #21452

    Akshatha Raju
    Participant

    Hello Klaus H ,

    You got my problem, however I am not able to find the solution to get the rows of DTO. I have tried ‘N’ number of ways to convert this JSON data into rows of DTO. I have used all methods like JSONObject, JSONArray, JSONTokener etc to get the required solution. But I am getting one or the other exception when i try to convert it into list of DTO. Can you please provide me a snippet where in you have converted JSON data to rows of DTO, and also can you provide me the exact ‘JAR’ file which I need to download and add in my ‘LIB’ folder in order to achieve this. Right now I have downloaded & used the following JAR file ‘java-json.jar’. Thanks in advance!

Viewing 8 posts - 1 through 8 (of 8 total)

You must be logged in to reply to this topic.