1

I want to send the firstname mike using json to an extjs grid, that reads json.However my knowledge in Json is limited,i don't know how to create the string firstname in json and i'm failing to achieve it.Any help please on how to do so?

//java code

import java.io.*; 

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpServlet;

import com.sun.org.apache.xml.internal.serialize.OutputFormat;
import com.sun.org.apache.xml.internal.serialize.XMLSerializer;

import net.sf.json.JSON;
import net.sf.json.JSONObject;
import net.sf.json.JSONSerializer;


public class JsonForm extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp)
    throws ServletException, IOException {



    }

}


//grid

Ext.onReady(function(){
    Ext.define('Employee',{
        extend: 'Ext.data.Model',
        proxy: {
            type: 'ajax',
            reader: 'json'
        },
        fields: [{
            name: 'FirstName',
            type: 'string'
        }]
    });


    var gridStore = Ext.create('Ext.data.XmlStore', {
      model: 'Employee',
      autoLoad: true,
      proxy: {
          type: 'ajax',
          url: '',

          reader: {
              type: 'json',
              root: ''

          }
       }
   });


    grid = Ext.create('Ext.grid.Panel', { 
      store: gridStore,
      columnLines: true,
      frame: true,
      columns: [
          {text: "First Name", flex:1, dataIndex: 'FirstName', tdCls: 'no-dirty'},


      ],
      renderTo:Ext.getBody(),
      width: '100%',
      height: 650
    });

});
Tarabass
  • 3,132
  • 2
  • 17
  • 35
dan
  • 593
  • 6
  • 19
  • http://stackoverflow.com/questions/2010990/how-do-you-return-a-json-object-from-a-java-servlet – yorlin Oct 01 '15 at 12:49

1 Answers1

0

I believe dataIndex value you have is not correct, you should use field's property name as the value for dataIndex.

dataIndex:'name' instead of what you have..

Take a look at this page from their docs, it might help more

http://docs.sencha.com/extjs/4.2.2/#!/api/Ext.grid.Panel

bullettrain
  • 958
  • 1
  • 9
  • 17