alphadog

Forum Replies Created

Viewing 6 replies - 16 through 21 (of 21 total)
  • Author
    Replies
  • in reply to: POST vs. GET #81970
    alphadog
    Participant

    Ah, yes. I didn’t look at the second line that had the revision number. Sorry, I have rev.8. I downloaded rev.28

    One thing to note, there is no way to add parameters to the JSON or XML request. You are limited to page, rowNum, sortname, sortorder and the timestamp.

    If you look in my solution above, you’ll note that I added a property and supporting methods that allows a user to create, manipulate and append any user-defined parameters to the above set of parameters in the grid’s request.

    I did modify my code above to bet better aligned with your gdata/mtype related code changes.

    I have merged my additions into your rev.28. If you would like a copy, I can send one to you. Just say where…

    in reply to: jqGrid conflicts with DDAccordion #81966
    alphadog
    Participant

    It’s on an intranet. Can I send it somewhere for you to view?

    in reply to: POST vs. GET #81963
    alphadog
    Participant

    I’m confused.

    I grepped/looked through the jqGrid (3.0.rc) codebase, and nowhere did I find any reference to a variable or string of “mtype”.

    Furthermore, your populate() function for XML type data is hardcoded to a GET in its $.ajax() call parameters. For JSON calls, the function $.getJSON() is inherently a GET operation.

    Where is mtype set and used?

    in reply to: POST vs. GET #81960
    alphadog
    Participant

    So, I think I fixed my own problems and, perhaps, expanded the functionality of jqGrid in the process? Nothing like rolling up your sleeves and digging in someone else’s code…

    First, I added a “postData” property in jqGrid()’s extend() function that initializes with an empty object {}:


    $.fn.jqGrid = function( p ) {
    p = $.extend({
    ...
    loadComplete: null, //Joe Tataro
    postData: {},
    editurl: null,
    ...
    }, p || {});

    Nextly, I added some function to manipulate that postData object and properties thereof. As it stands, the functions do not contain much error-checking. I do minimal checking on the setter only.


    /*---- start postData-related functions ---*/

    $.fn.getPostData = function(){
    return this[0].p.postData;
    };

    $.fn.setPostData = function( newdata ) {
    // check if newdata is correct type
    if ( typeof(newdata) === 'object' ) {
    this[0].p.postData = newdata;
    }
    else {
    alert("Error: cannot add a non-object postData value. postData unchanged.");
    }
    };

    $.fn.appendPostData = function( newdata ) {
    // check if newdata is correct type
    if ( typeof(newdata) === 'object' ) {
    $.extend(postData, newdata);
    }
    else {
    alert("Error: cannot append a non-object postData value. postData unchanged.");
    }
    };

    $.fn.setPostDataItem = function( key, val ) {
    this[0].p.postData[key] = val;
    };

    $.fn.getPostDataItem = function( key ) {
    return this[0].p.postData[key];
    };

    $.fn.removePostDataItem = function( key ) {
    delete this[0].p.postData[key];
    };

    /*---- end postData-related functions ---*/

    Finishly, I modded populate() and subgridpopulate() to work with the postData variable. This involved creating two new datatypes: “json/post” and “xml/post”. I simply combine the params from the existing GET implementation with the data in postData.


    var populate = function () {
    if(!grid.hDiv.loading) {
    grid.hDiv.loading = true;
    $("div.loading",grid.hDiv).fadeIn("fast");
    switch(ts.p.datatype)
    {
    case "json":
    $.getJSON(ts.p.url,{page: ts.p.page, rows: ts.p.rowNum, sidx: ts.p.sortname, sord:ts.p.sortorder}, function(JSON) { addJSONData(JSON,ts.grid.bDiv); if(loadComplete) loadComplete();});
    if( ts.p.loadonce ) ts.p.datatype = "local";
    break;
    case "xml":
    $.ajax({ url: ts.p.url,type:"GET",dataType:"xml",data :{page: ts.p.page, rows: ts.p.rowNum, sidx: ts.p.sortname, sord:ts.p.sortorder}, complete:function(xml) { addXmlData(xml.responseXML,ts.grid.bDiv);if(loadComplete) loadComplete();}});
    if( ts.p.loadonce ) ts.p.datatype = "local";
    break;
    /*---- start postData-related functions


    */
    case "json/post":
    $.post(ts.p.url, $.extend(ts.p.postData, {page:ts.p.page, rows:ts.p.rowNum, sidx:ts.p.sortname, sord:ts.p.sortorder}), function(JSON) { addJSONData(JSON,ts.grid.bDiv); if(loadComplete) loadComplete();}, "json");
    if( ts.p.loadonce ) ts.p.datatype = "local";
    break;
    case "xml/post":
    $.ajax({ url: ts.p.url,type:"POST",dataType:"xml",data:$.extend(ts.p.postData, {page:ts.p.page, rows:ts.p.rowNum, sidx:ts.p.sortname, sord:ts.p.sortorder}), complete:function(xml) { addXmlData(xml.responseXML,ts.grid.bDiv);if(loadComplete) loadComplete();}});
    if( ts.p.loadonce ) ts.p.datatype = "local";
    break;
    /*---- end postData-related functions


    */
    case "local":
    sortArrayData();
    break;
    }
    }
    return false;
    }

    Example of usage is:

    var ids = "";
    $("input[name='locIDSet']:checked").each( function(i) { ids = ids + "," + this.value; } ); //collects all checked checkboxes with name locIDSet
    jQuery("#list2").setPostDataItem( "ids", ids ); // adds to postData
    jQuery("#list2").setPage(1);
    jQuery("#list2").trigger('reloadGrid');

    Is this correct? Should it have been done some other way?

    in reply to: jqGrid conflicts with DDAccordion #81953
    alphadog
    Participant

    Just to be even clearer 🙂

    – jqGrid works fine by itself.
    – DDAccordion works fine by itself.
    – When both are in the same page, DDAccordion stomps all over jqGrid.

    in reply to: jqGrid conflicts with DDAccordion #81952
    alphadog
    Participant

    Thanks for the prompt reply. In answer:

    1. jqGrid does work if I keep DDAccordion out of the page. DDAccordion is definitely somehow conflicting with jqGrid, but I am not expert enough to quickly see where…

    2. Sorry, I was not clear, but “table” was just a placeholder in my post for the id of a table. To be more precise, I used the “Getting Started” example from this site where the table id is “list2”, thus $(“list2”).jqGrid() is the actual call. It works as lonf as I keep the ddaccordion.init() call out of the page.

Viewing 6 replies - 16 through 21 (of 21 total)

Stay connected with us in your favorite flavor!