cmcaba
cmcaba

Reputation: 115

Flexigrid doesn't display data

I recently started working on a web project.My requirements are to use Flexigrid Jquery plugin to render some chunks of data from a database. On the server side I use Jackson to format the data. My jquery script looks like this :

<script type="text/javascript">
$(document).ready(function() {
    $("#customers").flexigrid({
          url: 'JsonHandler',
          dataType: 'json',
          colModel : [
            {display: 'Id', name : 'userid',},
            {display: 'Name', name : 'fullname',},
            ],
          title: 'Table',
          width: 700,
          height: 200
        });   
        });
</script>

The server sends valid Json data to the browser(this is what I get in Firebug) :

[{"userid":"a","fullname":"John Doe"},
 {"userid":"b","fullname":"Mark Brown"},
 {"userid":"c","fullname":"Mads Borsen"}]

For some reason my table is still empty. If you have some suggestion, please help.

I assume that the name option from colModel needs to match exactly the key in the json data, for my case userid and fullname.

Could it be related to the character encoding ?

Thanks!

Upvotes: 2

Views: 2598

Answers (1)

Manu Santillan
Manu Santillan

Reputation: 86

the format that FLEXIGRID needs to render is something like this

{"page":"1","total":"1","rows": 
[ 
  {"id":"1","cell":["1","55144602","Z014162","C"]},
  {"id":"3","cell":["3","55189392","Z014162","C"]},
  {"id":"4","cell":["4","55189393","Z014162","C"]},
  {"id":"5","cell":["5","55189394","Z014162","C"]},
  {"id":"6","cell":["6","55189395","Z014162","C"]}
]}

You need to include the "page", "total" and "rows" fields, also the "id", and "cell" fields. The values contained in the brackets of "cell":[] are the values that flexigrid use to render or fill the grid, I simulate the answer with a jsp file for testing purposes, My grid has 4 fields, and as you can see, they are filled with the values of each cell field of the answer.

Im building an object that JACKSON could render, but Im still working on it, The only clue I have to achieve this is that if you send an ArrayList jackson returns a [] response, if you only return an Oject, or a JavaBean it returns a {} response.

Hope this info Helps.

Manuel Santillan El Leon

Upvotes: 3

Related Questions