Note that there are some explanatory texts on larger screens.

plurals
  1. POjqGrid fill grid with data
    text
    copied!<p>I need to fill my jqGrid with data received from ajax call. Here is my jqGrid code:</p> <pre><code>$("#discuss_table_answers").jqGrid({ datatype: "local", jsonReader: { root: "list", repeatitems: false, records: "size" }, colNames: ['agentId', 'date', 'deleted', 'id', 'questionId', 'rating', 'reported', 'text'], colModel: [ {name: 'agentId', index: 'agentId', width: 80, align: 'right', formatter:"number"}, {name: 'date', index: 'date', width: 80, align: 'right', formatter:"date"}, {name: 'deleted', index: 'deleted', width: 150, sortable: true , formatter: function myformatter(cellvalue, options, rowObject) { if (cellvalue) { return "&lt;p&gt;Rejected&lt;/p&gt;"; } return "&lt;button class='reject_question' style='height: 20px;width: 100px'&gt;Reject&lt;/button&gt;"; } }, {name: 'id', index: 'id', width: 55,formatter:"number"}, {name: 'questionId', index: 'questionId', width: 90,formatter:"number"}, {name: 'rating', index: 'rating', width: 150, sortable: false,formatter:"number"}, {name: 'reported', index: 'reported', width: 150, sortable: false}, {name: 'text', index: 'text', width: 80, align: 'right'} ], height: "100%" }); </code></pre> <p>Function code for adding data:</p> <pre><code>function addData (rowId) { var ansTable = $("#discuss_table_answers"); ansTable.clearGridData(true); $.getJSON("review2-admin/question/" + rowId + "/answers", function (data) { console.log(data); console.log(data['list'].length); ansTable.setGridParam({data: data}).trigger('reloadGrid'); }); </code></pre> <p>From firebug i see that I got a proper answer from the server:</p> <pre><code>{"size":2,"list":[{"id":15,"questionId":9,"agentId":7327516,"text":"лоол","date":1364882946000,"reported":false,"deleted":false,"rating":0},{"id":12,"questionId":9,"agentId":4405127,"text":"456456456","date":1364793241000,"reported":false,"deleted":false,"rating":2}]} </code></pre> <p>So the problem is that data got from server not displayed in the grid.</p> <p>I tried to use test data like <code>var testData = [ {list: {agentId: "7327516", date: "1364882946000", deleted: false, id: "15", questionId: "9", rating: "0", reported: false, text: "лоол"}, size: 1} ];</code> and it worked fine, table got refreshed. </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload