开发者

jqGrid not displaying data, no errors

OK, this mostly works as far as my PHP action is called and returns the JSON data from the query just fine. The problem is jqGrid won't display the data. What am I missing? I have read every article here and elsewhere on the subject I can find. This looks like it should work.

HTML:

<table id="dsisBaseTable"></table>
<div id=dsisBasePager"></div>

Here is my grid definition (the whole JavaScript function):

function runGridBaseReport() {
    $('#DSISBaseReportResult').html('<table id="dsisBaseTable"></table>' +
        '<div id="dsisBasePager"></div> ');
    $('#DSISBusy').fadeIn();
    var loc = $('#dsisLocation').val();
    var f = (loc == '') ? '' : loc.substring(0, 1);
    if (f.match(/[A-Z]/) || f.match(/[a-z]/))
    loc = loc.substring(1);

    var dsisParams = {
        mode : 'basereport',
        dsisLocation : loc,
        dsisGuild : $('#dsisGuild').val(),
        dsisNick : $('#dsisNick').val(),
        dsisOccGuild : $('#dsisOccGuild').val(),
        dsisOccNick : $('#dsisOccNick').val(),
        dsisMinLevel : $('#dsisMinLevel').val(),
        dsisMaxLevel : $('#dsisMaxLevel').val(),
        dsisEconomy : $('#dsisEconomy').val(),
        dsisDt : $('#dsisDt').val(),
        dsisDs : $('#dsisDs').val(),
        dsisPr : $('#dsisPr').val(),
        dsisPs : $('#dsisPs').val(),
        dsisMinFleet : $('#dsisMinFleet').val(),
        dsisMaxFleet : $('#dsisMaxFleet').val(),
        dsisCapitol : $('#dsisCapitol').is(':checked'),
        dsisWormHole : $('#dsisWormHole').is(':checked'),
        dsisAeFormat : $('#dsisAeFormat').is(':checked')
        };
    var data = { data: jsonString(dsisParams)};

    $("#dsisBaseTable").jqGrid({
        url: indexUrl + '/basereport',
        datatype: 'json',
        postData: data,
        mtype: 'POST',
        colNames:['Name',
                  'Location',
                  'WH',
                  'Inc',
                  'Eco',
                  'Guild',
                  'Owner',
                  'Level',
                  'Guild',
                  'OccBy',
                  'JG(Log)',
                  'CC',
                  'PH',
                  'DS',
                  'DT',
                  'PS',
                  'PR',
                  'DB',
                  'Fleet',
                  'Days',
                  'Updated By'],
        colModel :[
          {name:'baseName',
            index:'baseName',
            sortable: false,
            width: 50,
            jsonmap: 'row.baseName'},
          {name:'location',
            index:'location',
            width: 50,
            jsonmap: 'row.location'},
          {name:'wh',
            index:'wh',
            width: 50,
            jsonmap: 'row.wormhole'},
          {name:'inc',
            index:'inc',
            align:'right',
            width: 50,
            jsonmap: 'row.income'},
          {name:'eco',
            index:'eco',
            align:'right',
            width: 50,
            jsonmap: 'row.economy'},
          {name:'ownerGuild',
            index:'ownerGuild',
            width: 50,
            jsonmap: 'row.ownerGuild'},
          {name:'ownerNick',
            index:'ownerNick',
            width: 50,
            jsonmap: 'row.ownerNick'},
          {name:'ownerLevel',
            index:'ownerLevel',
            width: 50,
            jsonmap: 'row.ownerLevel'},
          {name:'occGuild',
            index:'occGuild',
            width: 50,
            jsonmap: 'row.occGuild'},
          {name:'occNick',
            index:'occNick',
            width: 50,
            jsonmap: 'row.occNick'},
          {name:'jumpGate',
            index:'jumpGate',
            width: 50,
            jsonmap: 'row.jumpGate'},
          {name:'commandCenter',
            index:'commandCenter',
            width: 50,
            jsonmap: 'row.commandCenter'},
          {name:'photons',
            index:'photons',
            width: 50,
            jsonmap: 'row.photons'},
          {name:'dshield',
            index:'dshields',
            width: 50,
            jsonmap: 'row.dshields'},
          {name:'disruptors',
            index:'disruptors',
            width: 50,
            jsonmap: 'row.disruptors'},
          {name:'pshields',
            index:'pshields',
            width: 50,
            jsonmap: 'row.pshields'},
          {name:'prings',
            index:'prings',
            width: 50,
            jsonmap: 'row.prings'},
          {name:'debris',
            index:'debris',
            width: 50,
            jsonmap: 'row.debris'},
          {name:'fleetSize',
            index:'fleetSize',
            width: 50,
            jsonmap: 'row.fleetSize'},
          {name:'daysOld',
            index:'daysOld',
            width: 50,
            jsonmap: 'row.daysOld'},
          {name:'updatedBy',
            index:'updatedBy',
            sortable: false,
            width: 50,
            jsonmap: 'row.updatedBy'}
        ],
        pager: $('#dsisBasePager'),
        rowNum: $('#basePageSize').val(),
        rowList:[20,30,40,50],
        sortn开发者_JS百科ame: 'location',
        sortorder: 'asc',
        viewrecords: true,
        caption: 'Base Report',
        width: 1024,
        height: 300,
        jsonReader : {
            root: "rows",
            page: "page",
            total: "total",
            records: "records",
            repeatitems: false,
            id: "id"
        }
    });
    /*    pages'   => round($totRows/$dsisPageSize),
         'page'    => $dsisPage,
         'total'   => $numRows/$dsisPage,
         'records' => $totRows,
         'rows' */
    $('#DSISBusy').fadeOut();
    $('#DSISBaseReportResult').fadeIn();
    return false;
}

This is how I process the request and return the results:

public function basereportAction()
{
    try
    {
      $params = $this->_getAllParams();
      //Log::logErr('params:'.print_r($params, true));

      $data = $this->_getParam('data');
      //Log::logErr('Data:'.print_r($data, true));

      $reportParams->request = json_decode($data);
      //Log::logErr('DSIS Obj:'.print_r($obj, true));

      $reportParams->request->dsisPage = $this->_getParam('page');
      $reportParams->request->dsisPageSize = $this->_getParam('rows');
      $reportParams->request->dsisOrderBy = $this->_getParam('sidx');
      $reportParams->request->dsisSortDir = $this->_getParam('sord');

      $base = new Base();
      // $result is a PHP array
      $result = $base->outputDSISReportHtml($reportParams, true);

      $js = json_encode($result);
      Log::logErr('JSON:'.$js);

      $callback = $this->_getParam('callback');

      echo $js;
    }
    catch( Exception $e)
    {
        Log::logErr('DSISReportController::basereport:Error:'.$e->getMessage());
        throw $e;
    }
}

This is my data:

{
    "total": 0,
    "page": "1",
    "records": 1,
    "rows": [
        {
            "id": 0,
            "row": {
                "baseName": "Stratos",
                "location": "J15:32:53:41",
                "wormhole": "",
                "income": 78,
                "economy": 78,
                "ownerGuild": "CDA",
                "ownerNick": "D-Day 9000",
                "ownerLevel": "17.14",
                "occGuild": "",
                "occNick": "",
                "jumpGate": 0,
                "commandCenter": 1,
                "photons": "0",
                "dshields": "0",
                "disruptors": "0",
                "pshields": "0",
                "prings": "0",
                "debris": 0,
                "fleetSize": "22250",
                "daysOld": 11,
                "updatedBy": 3057
            }
        }
    ]
}


The only error I see in the end of your JSON data ended with "},]}". You should remove the comma before ']'.

After mininal changes to be able to reproduce your test example your demo works without any visible problems.

UPDATED: The same demo with new JSON data works also without any problem. I suppose the error is in the part of code which you not posted here. For exemple, I placed your code inside of jQuery(document).ready(function () {/*the code*/});. I have to remove postData parameter because its value data which you use in your code are not defined. Exactly in the same reason the indexUrl variable used in url parameter I had to change. The parameter rowNum:$('#basePageSize').val() looks also strange and I replaced it to the rowNum:20. If you could post the url to the working (not workin) original solution or really full HTML and JavaScript code one could probably help you.


I had the same problem. The exhibited jqgrid not return XML. I noticed that the registry database had some special characters like "&". The problem was the browser. Decided as follows by placing the CDATA tag field return in XML:

sb.Append ("<cell>"); sb.Append ("<! [CDATA [" + g.Name + "]"); sb.Append ("]> </ cell>");
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜