Monday, October 8, 2012

Json Codes

 buttonJson

function extjsfunc(){

Ext.require([
    'Ext.tab.*'
    ,'Ext.window.*'
    ,'Ext.tip.*'
    ,'Ext.layout.container.Border'
    ,'Ext.window.MessageBox'   
    ,'Ext.grid.*'
    ,'Ext.data.*'
    ,'Ext.util.*'
    ,'Ext.state.*'
    ,'Ext.form.*'
]);
Ext.onReady(function(){

Ext.define('model_1',{
      extend:'Ext.data.Model',
      fields:[
              {name: 'name'},
                {name: 'dept'},          
                {name: 'opchrg'},
             ]
   });
var store = new Ext.data.JsonStore({
    proxy: {
        url: 'getJson.jsp',
        type: 'ajax',
        reader: {
            type: 'json',
            root: 'model_1'
        }
    },
    fields: ['name', 'dept','opchrg']
});

     // create the grid
 var grid = new Ext.grid.GridPanel({
        store: store,
        columns: [
            //{id:'id',header: 'ID', width: 30, sortable: true, dataIndex: 'id'},
            {header: "Name", width: 60, dataIndex: 'name', sortable: true},
            {header: "Dept", width: 60, dataIndex: 'dept', sortable: true},
            {header: "Opchrg", width: 60, dataIndex: 'opchrg', sortable: true},
        ],
        renderTo:'editor-grid',
        width:540,
        height:200
    });

});

}

</script>

<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <script>
        // use the scoped CSS stylesheet if the url has a scopecss parameter
      document.write('<link rel="stylesheet" type="text/css" href="extjs/resources/css/ext-all' +
            ((window.location.search.indexOf('scopecss') === -1) ? '' : '-scoped') + '.css" />');  
    </script>
   <link rel="stylesheet" type="text/css" href="extjs/shared/example.css" />
   <link rel="stylesheet" type="text/css" href="extjs/ux/css/CheckHeader.css" /> 
    <!--<script type="text/javascript" src="library/ext-all.js"></script> -->
    <script type="text/javascript" src="library/ext-all-debug.js"></script>
</head>    
<input type ="button" id="srchbtn" onclick="extjsfunc()" class="extra" value="Search">

<div id="editor-grid"></div>



getJson:

<%@page import="db.*"%>
<%@page import="org.json.JSONArray"%>
<%@page import="java.io.PrintWriter"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
   <%
                    str = "SELECT * FROM dept1";
                   
                    dept objdept = new dept();
                    String ar_rs[] = objdept.displayValue(str);
                    JSONArray jsonObj=new JSONArray();
                    int i=0;
                    while(i< ar_rs.length)
                    {
                        jsonObj.put(i,ar_rs[i]);
                        i++;
                    }
                    out.println(jsonObj);
                
        %>
    

0 comments:

Post a Comment