AnsweredAssumed Answered

extjs grid + json+ webscript

Question asked by marcuzzo86 on Aug 10, 2009
Latest reply on Aug 11, 2009 by marcuzzo86
hi guys i have a question for you.
i'm trying to retrieve data from alfresco via webscript and then put it in a ExtJS grid.
my webscript work fine, these are :
- descriptor file:
<webscript>
  <shortname>prova</shortname>
  <description>Lists all documents with type: FATTURA ATTIVA</description>
  <url>/marco/search</url>
  <format default="json">extension</format>
  <authentication>user</authentication>
  <transaction>required</transaction>
</webscript>

- free marker template file:
{
   total: ${total},
   rows: [
   <#list nodes as document>
           {"id": "${document.nodeRef}", "name": "${document.name}"}
   </#list>
   ]
}

-and javascript file:
var type='TYPE:"{http://www.marco.com/model/content/1.0}fatt_a"';
nodes = search.luceneSearch(type);

var start = 0;
var limit = 100;

if (args.start != undefined) {
   start = args.start;
}

if (args.limit != undefined) {
   limit = args.limit;
}

pagedResults = new Array();
for (i=0; i < nodes.length && i < limit; i++ ) {
   var node = nodes[(+start + i)];
   if (node != undefined) {
      pagedResults.push(node);
   }
}

model.nodes = pagedResults;
model.total = nodes.length;

how can you see it is a very simple webscript that return a list of document.
the view files are these:

-the javascript file that ask alfresco and then create the grid:

Ext.onReady(function() {
var record = Ext.data.Record.create([ //definisco la forma del record
    {id: 'id', name: 'name'},                 
]);

var myReader = new Ext.data.JsonReader({
    totalProperty: "total",             // numero righe
    root: "rows",                         // lista dei dati da esporre (label del file json)
}, record);

   var grid = new Ext.grid.GridPanel({
      store: new Ext.data.Store({
                 // load using HTTP
            proxy: new Ext.data.HttpProxy({url: 'http://localhost:8080/alfresco/service/opsoro/search'}), //effettuo al richiesta
            reader: myReader //oggetto JSONreader
      }),
      columns: [
         {header: 'ID', width: 120, sortable: true, dataIndex: 'id'},
         {header: 'Name', width: 120, sortable: true, dataIndex: 'name'},
      ],
      viewConfig: {
         forceFit: true
      },
      renderTo: 'content',
      title: 'mannaggia de la pulchiacchera!!!!',
      width: 500,
      height: 500,
      frame: true
   });

   grid.getSelectionModel().selectFirstRow();
});

- and the html:
<html>
<head>
    <title>Grid</title>
   
    <!– Include Ext and app-specific scripts: –>
    <script type="text/javascript" src="../adapter/ext/ext-base.js"></script>
    <script type="text/javascript" src="../ext-all-debug.js"></script>
    <script type="text/javascript" src="griglia.js"></script>
   
    <!– Include Ext stylesheets here: –>
    <link rel="stylesheet" type="text/css" href="../resources/css/ext-all.css">
    <link rel="stylesheet" type="text/css" href="griglia.css">
</head>
<body>
   <h1>Griglia dinamica</h1>
   <div id="content">
   </div>

</body>
</html>

The html return an empty grid! what is the problem?????? thanks!

Outcomes