天天看點

Ext js 應用系列二:Page Grid

在做page grid時也很郁悶,開始以為隻用引用Ext js的page grid對象翻頁等都會自動搞定,沒想到,翻頁操作還是要通過伺服器端代碼生成,Ext js隻是負責傳送start,limit等參數等。。。艾,高估它了。

在notes中應用page grid,我主要用了以下設計元素,表單,視圖,代理和LS lib庫

1、表單,用于顯示page grid

Ext js 應用系列二:Page Grid

< div  id ="dlg-box"  style ="visibility:hidden;position:absolute;top:0px;" >

Ext js 應用系列二:Page Grid

     < div  class ="x-dlg-hd" > Select Expired Server </ div >

Ext js 應用系列二:Page Grid

     < div  class ="x-dlg-bd" >

Ext js 應用系列二:Page Grid

     < div  id ="page-grid"  style ="border:1px solid #99bbe8;overflow: hidden; width: 665px; height: 300px;" ></ div >

Ext js 應用系列二:Page Grid

     </ div >

Ext js 應用系列二:Page Grid

</ div >

js檔案如下,其中有對Ext Dialog box 的處理,因為我的Page Grid在Dialogbox中顯示。

Ext js 應用系列二:Page Grid
Ext js 應用系列二:Page Grid
Ext js 應用系列二:Page Grid
Ext js 應用系列二:Page Grid
Ext js 應用系列二:Page Grid
Ext js 應用系列二:Page Grid

function  displayDialog() ... {

Ext js 應用系列二:Page Grid

    var thisform = document.forms[0];

Ext js 應用系列二:Page Grid

    var key = thisform.mLineItemKey.value;

Ext js 應用系列二:Page Grid
Ext js 應用系列二:Page Grid

    //Move selected records

Ext js 應用系列二:Page Grid
Ext js 應用系列二:Page Grid

    function doMove(isOK)...{

Ext js 應用系列二:Page Grid

        if(isOK=="yes")   

Ext js 應用系列二:Page Grid
Ext js 應用系列二:Page Grid

        ...{       

Ext js 應用系列二:Page Grid

                 var m = grid.getSelections(); 

Ext js 應用系列二:Page Grid

                 //Set the value of key

Ext js 應用系列二:Page Grid

                 m[0].set('key',key);

Ext js 應用系列二:Page Grid

                 var jsonData = '[' + Ext.util.JSON.encode(m[0].data);   

Ext js 應用系列二:Page Grid

                 for(i=1;i<m.length;i++)

Ext js 應用系列二:Page Grid
Ext js 應用系列二:Page Grid

                 ...{ 

Ext js 應用系列二:Page Grid

                   //Set the value of key

Ext js 應用系列二:Page Grid

                   m[i].set('key',key);  

Ext js 應用系列二:Page Grid

                 jsonData = jsonData + ',' + Ext.util.JSON.encode(m[i].data);                 

Ext js 應用系列二:Page Grid

                 }   

Ext js 應用系列二:Page Grid

                 jsonData = jsonData + ']' ;    

Ext js 應用系列二:Page Grid
Ext js 應用系列二:Page Grid

            var con = new Ext.data.Connection();

Ext js 應用系列二:Page Grid
Ext js 應用系列二:Page Grid

            con.request(...{

Ext js 應用系列二:Page Grid

                url: dbpath+'wxExpiredServer?openAgent&action=updatefield&rdm'+getRandom(),

Ext js 應用系列二:Page Grid
Ext js 應用系列二:Page Grid

                params: ...{data:jsonData},

Ext js 應用系列二:Page Grid
Ext js 應用系列二:Page Grid

                callback: function (opts, success, response)...{

Ext js 應用系列二:Page Grid
Ext js 應用系列二:Page Grid

                    if(success) ...{

Ext js 應用系列二:Page Grid

                        var returnValue = getXmlNodeValue(response.responseXML,"response");

Ext js 應用系列二:Page Grid

                        if(returnValue.toLowerCase()!="success")

Ext js 應用系列二:Page Grid

                            alert(returnValue);

Ext js 應用系列二:Page Grid
Ext js 應用系列二:Page Grid

                        else...{

Ext js 應用系列二:Page Grid

                            alert('Records Move Successfully!');

Ext js 應用系列二:Page Grid

                            ds.reload();        

Ext js 應用系列二:Page Grid

                            gds.reload();        

Ext js 應用系列二:Page Grid

                        }

Ext js 應用系列二:Page Grid

                    }

Ext js 應用系列二:Page Grid

                }

Ext js 應用系列二:Page Grid

            })     

Ext js 應用系列二:Page Grid

         }   

Ext js 應用系列二:Page Grid

         else  

Ext js 應用系列二:Page Grid
Ext js 應用系列二:Page Grid

         ...{    

Ext js 應用系列二:Page Grid

             grid.getSelectionModel().clearSelections();            

Ext js 應用系列二:Page Grid

        }          

Ext js 應用系列二:Page Grid

    }

Ext js 應用系列二:Page Grid
Ext js 應用系列二:Page Grid
Ext js 應用系列二:Page Grid

    function onMoveClick()...{

Ext js 應用系列二:Page Grid

         var m = grid.getSelections();   

Ext js 應用系列二:Page Grid

         if(m.length > 0)   

Ext js 應用系列二:Page Grid
Ext js 應用系列二:Page Grid

         ...{   

Ext js 應用系列二:Page Grid

             Ext.MessageBox.confirm('Message', 'Are sure to move?' , doMove);      

Ext js 應用系列二:Page Grid

         }   

Ext js 應用系列二:Page Grid

         else  

Ext js 應用系列二:Page Grid
Ext js 應用系列二:Page Grid

         ...{   

Ext js 應用系列二:Page Grid

             Ext.MessageBox.alert('Message', 'Please select your records!');   

Ext js 應用系列二:Page Grid

         }   

Ext js 應用系列二:Page Grid

    }

Ext js 應用系列二:Page Grid
Ext js 應用系列二:Page Grid

    //Show Dialog

Ext js 應用系列二:Page Grid
Ext js 應用系列二:Page Grid

    function showDialog()...{

Ext js 應用系列二:Page Grid

    //Create Dialog

Ext js 應用系列二:Page Grid
Ext js 應用系列二:Page Grid

        var dialog = new Ext.BasicDialog("dlg-box", ...{ 

Ext js 應用系列二:Page Grid

            autoTabs:true,

Ext js 應用系列二:Page Grid

            width: 690,

Ext js 應用系列二:Page Grid

              height: 375,

Ext js 應用系列二:Page Grid

              shadow: true,

Ext js 應用系列二:Page Grid

              minWidth: 300,

Ext js 應用系列二:Page Grid

              minHeight: 250,

Ext js 應用系列二:Page Grid

              proxyDrag: true

Ext js 應用系列二:Page Grid

         });    

Ext js 應用系列二:Page Grid

        dialog.addKeyListener(27, dialog.hide, dialog);

Ext js 應用系列二:Page Grid

          dialog.addButton('Close', dialog.hide, dialog);

Ext js 應用系列二:Page Grid

          dialog.show();

Ext js 應用系列二:Page Grid

    }

Ext js 應用系列二:Page Grid
Ext js 應用系列二:Page Grid

    //Create Record

Ext js 應用系列二:Page Grid

    var Row = Ext.data.Record.create([

Ext js 應用系列二:Page Grid
Ext js 應用系列二:Page Grid

             ...{name: 'key'},

Ext js 應用系列二:Page Grid
Ext js 應用系列二:Page Grid

           ...{name: 'unid'},

Ext js 應用系列二:Page Grid
Ext js 應用系列二:Page Grid

           ...{name: 'product'},

Ext js 應用系列二:Page Grid
Ext js 應用系列二:Page Grid

           ...{name: 'cpu'},

Ext js 應用系列二:Page Grid
Ext js 應用系列二:Page Grid

           ...{name: 'memory'},

Ext js 應用系列二:Page Grid
Ext js 應用系列二:Page Grid

           ...{name: 'harddisk'},

Ext js 應用系列二:Page Grid
Ext js 應用系列二:Page Grid

         ...{name: 'serialnum'},

Ext js 應用系列二:Page Grid
Ext js 應用系列二:Page Grid

         ...{name: 'acqdate'}

Ext js 應用系列二:Page Grid

      ]);

Ext js 應用系列二:Page Grid
Ext js 應用系列二:Page Grid

    // create the Data Store

Ext js 應用系列二:Page Grid
Ext js 應用系列二:Page Grid

    var ds = new Ext.data.Store(...{

Ext js 應用系列二:Page Grid

        // this page, an HttpProxy would be better

Ext js 應用系列二:Page Grid
Ext js 應用系列二:Page Grid

        proxy: new Ext.data.HttpProxy(...{url: dbpath+"wxExpiredServer?openAgent&action=displaypage&view=xmlExpiredServer&rdm="+getRandom()}),

Ext js 應用系列二:Page Grid
Ext js 應用系列二:Page Grid

        // create reader that reads the records

Ext js 應用系列二:Page Grid
Ext js 應用系列二:Page Grid

        reader: new Ext.data.XmlReader(...{

Ext js 應用系列二:Page Grid

               record: 'row',

Ext js 應用系列二:Page Grid

               id: 'unid',

Ext js 應用系列二:Page Grid

               totalRecords: 'totalCount'

Ext js 應用系列二:Page Grid

           }, Row)

Ext js 應用系列二:Page Grid

    });

Ext js 應用系列二:Page Grid
Ext js 應用系列二:Page Grid

    // the column model has information about grid columns

Ext js 應用系列二:Page Grid

    // the data store

Ext js 應用系列二:Page Grid
Ext js 應用系列二:Page Grid

    var cm = new Ext.grid.ColumnModel([...{

Ext js 應用系列二:Page Grid

           header: "KEY",

Ext js 應用系列二:Page Grid

           dataIndex: 'key',

Ext js 應用系列二:Page Grid

           width: 50,

Ext js 應用系列二:Page Grid

           hidden: true

Ext js 應用系列二:Page Grid
Ext js 應用系列二:Page Grid

        },...{

Ext js 應用系列二:Page Grid

           header: "UNID",

Ext js 應用系列二:Page Grid

           dataIndex: 'unid',

Ext js 應用系列二:Page Grid

           width: 50,

Ext js 應用系列二:Page Grid

           hidden: true

Ext js 應用系列二:Page Grid
Ext js 應用系列二:Page Grid

        },...{

Ext js 應用系列二:Page Grid

           header: "Product",

Ext js 應用系列二:Page Grid

           dataIndex: 'product',

Ext js 應用系列二:Page Grid

           width: 250

Ext js 應用系列二:Page Grid
Ext js 應用系列二:Page Grid

        },...{

Ext js 應用系列二:Page Grid

           header: "CPU",

Ext js 應用系列二:Page Grid

           dataIndex: 'cpu',

Ext js 應用系列二:Page Grid

           width: 100

Ext js 應用系列二:Page Grid
Ext js 應用系列二:Page Grid

        },...{

Ext js 應用系列二:Page Grid

           header: "Memory",

Ext js 應用系列二:Page Grid

           dataIndex: 'memory',

Ext js 應用系列二:Page Grid

           width: 100

Ext js 應用系列二:Page Grid
Ext js 應用系列二:Page Grid

        },...{

Ext js 應用系列二:Page Grid

           header: "Hard Disk",

Ext js 應用系列二:Page Grid

           dataIndex: 'harddisk',

Ext js 應用系列二:Page Grid

           width: 150

Ext js 應用系列二:Page Grid
Ext js 應用系列二:Page Grid

        },...{

Ext js 應用系列二:Page Grid

           header: "Serial No.",

Ext js 應用系列二:Page Grid

           dataIndex: 'serialnum',

Ext js 應用系列二:Page Grid

           width: 150

Ext js 應用系列二:Page Grid
Ext js 應用系列二:Page Grid

        },...{

Ext js 應用系列二:Page Grid

           header: "Acquisition Date",

Ext js 應用系列二:Page Grid

           dataIndex: 'acqdate',

Ext js 應用系列二:Page Grid

           width: 100

Ext js 應用系列二:Page Grid

        }]);

Ext js 應用系列二:Page Grid
Ext js 應用系列二:Page Grid

    // by default columns are sortable

Ext js 應用系列二:Page Grid

    cm.defaultSortable = true;

Ext js 應用系列二:Page Grid
Ext js 應用系列二:Page Grid

    // create the page grid

Ext js 應用系列二:Page Grid
Ext js 應用系列二:Page Grid

    var grid = new Ext.grid.Grid('page-grid', ...{

Ext js 應用系列二:Page Grid

        ds: ds,

Ext js 應用系列二:Page Grid

        cm: cm,

Ext js 應用系列二:Page Grid

        loadMask: true

Ext js 應用系列二:Page Grid

    });

Ext js 應用系列二:Page Grid
Ext js 應用系列二:Page Grid

    // render it

Ext js 應用系列二:Page Grid

    grid.render();

Ext js 應用系列二:Page Grid
Ext js 應用系列二:Page Grid

    var gridFoot = grid.getView().getFooterPanel(true);

Ext js 應用系列二:Page Grid
Ext js 應用系列二:Page Grid

    // add a paging toolbar to the grid's footer

Ext js 應用系列二:Page Grid
Ext js 應用系列二:Page Grid

    var paging = new Ext.PagingToolbar(gridFoot, ds, ...{

Ext js 應用系列二:Page Grid

        pageSize: 25,

Ext js 應用系列二:Page Grid

        displayInfo: true,

Ext js 應用系列二:Page Grid

        displayMsg: 'Displaying records {0} - {1} of {2}',

Ext js 應用系列二:Page Grid

        emptyMsg: "No records"

Ext js 應用系列二:Page Grid

    });

Ext js 應用系列二:Page Grid

    // add the view button

Ext js 應用系列二:Page Grid
Ext js 應用系列二:Page Grid

    paging.addButton(...{

Ext js 應用系列二:Page Grid

        text: 'Move',

Ext js 應用系列二:Page Grid

        handler:onMoveClick

Ext js 應用系列二:Page Grid

    });

Ext js 應用系列二:Page Grid

    // trigger the data store load

Ext js 應用系列二:Page Grid
Ext js 應用系列二:Page Grid

    ds.load(...{params:...{start: 0, limit: 25}});

Ext js 應用系列二:Page Grid

    showDialog();

Ext js 應用系列二:Page Grid

} ;

2、視圖用于生成xml檔案

Ext js 應用系列二:Page Grid

" < row > "

Ext js 應用系列二:Page Grid

+ " < key > " + @Text(mLineItemKey) + " </ key > "

Ext js 應用系列二:Page Grid

+ " < unid > " + @Text(@DocumentUniqueID) + " </ unid > "

Ext js 應用系列二:Page Grid

+ " < product > " + @Text(mProductName)+ " </ product > "

Ext js 應用系列二:Page Grid

+ " < cpu > " + @Text(mCPU)+ " </ cpu > "

Ext js 應用系列二:Page Grid

+ " < memory > " + @Text(mMemory) + " </ memory > "

Ext js 應用系列二:Page Grid

+ " < harddisk > " + @Text(mHardDisk) + " </ harddisk > "

Ext js 應用系列二:Page Grid

+ " < serialnum > " + @Text(mSerialNum) + " </ serialnum > "

Ext js 應用系列二:Page Grid

+ " < acqdate > " + @Text(mAcqDate) + " </ acqdate > "

Ext js 應用系列二:Page Grid

+ " </ row > " + @NewLine

3、代理用于處理操作

Ext js 應用系列二:Page Grid
Ext js 應用系列二:Page Grid

Sub Initialize() Sub Initialize

Ext js 應用系列二:Page Grid

    On Error Goto errHandle

Ext js 應用系列二:Page Grid

    Dim CurLocation As String

Ext js 應用系列二:Page Grid

    CurLocation = "Agent.wxServerProduct"

Ext js 應用系列二:Page Grid
Ext js 應用系列二:Page Grid

    Dim session As New NotesSession

Ext js 應用系列二:Page Grid

    Dim note As NotesDocument

Ext js 應用系列二:Page Grid

    Dim db As NotesDatabase

Ext js 應用系列二:Page Grid
Ext js 應用系列二:Page Grid

    Set note = session.DocumentContext

Ext js 應用系列二:Page Grid

    Set db = note.ParentDatabase

Ext js 應用系列二:Page Grid
Ext js 應用系列二:Page Grid

    Dim ajaxRequest As AjaxRequest

Ext js 應用系列二:Page Grid

    Set ajaxRequest = New AjaxRequest(note)

Ext js 應用系列二:Page Grid
Ext js 應用系列二:Page Grid

    Dim action As String

Ext js 應用系列二:Page Grid

    action = ajaxRequest.getAction()

Ext js 應用系列二:Page Grid
Ext js 應用系列二:Page Grid

    Dim jsonString As String

Ext js 應用系列二:Page Grid

    Dim json As JSON

Ext js 應用系列二:Page Grid

    Dim jObjs As Variant

Ext js 應用系列二:Page Grid

    Dim json2Note As String

Ext js 應用系列二:Page Grid
Ext js 應用系列二:Page Grid

    Dim view As NotesView

Ext js 應用系列二:Page Grid

    Dim category As String

Ext js 應用系列二:Page Grid
Ext js 應用系列二:Page Grid

    If Lcase(action) = "displaypage" Then    

Ext js 應用系列二:Page Grid

        Set view = db.GetView(ajaxRequest.getView)

Ext js 應用系列二:Page Grid

        If Not view Is Nothing Then

Ext js 應用系列二:Page Grid

            Call ajaxRequest.getXmlPageView(view, ajaxRequest.getCategory, Cint(ajaxRequest.getStart()),_

Ext js 應用系列二:Page Grid

            Cint(ajaxRequest.getLimit()))    

Ext js 應用系列二:Page Grid

        End If

Ext js 應用系列二:Page Grid
Ext js 應用系列二:Page Grid

    End If

Ext js 應用系列二:Page Grid
Ext js 應用系列二:Page Grid

    If Lcase(action) = "updatefield" Then

Ext js 應用系列二:Page Grid
Ext js 應用系列二:Page Grid

        Set json = New JSON()

Ext js 應用系列二:Page Grid

        jsonString = ajaxRequest.getDecodedJsonString()

Ext js 應用系列二:Page Grid
Ext js 應用系列二:Page Grid

        jObjs = json.Parse(jsonString)

Ext js 應用系列二:Page Grid
Ext js 應用系列二:Page Grid

        json2Note = ajaxRequest.updateFieldJsonToNote(note.ParentDatabase,"mLineItemKey","key",jObjs)

Ext js 應用系列二:Page Grid

        If Len(json2Note) > 0 Then

Ext js 應用系列二:Page Grid

            Call bbstkLogError(CurLocation, 0, 0, json2Note)

Ext js 應用系列二:Page Grid

            ajaxRequest.xmlResponse("Failure:"+json2Note)

Ext js 應用系列二:Page Grid

            Exit Sub

Ext js 應用系列二:Page Grid

        Else

Ext js 應用系列二:Page Grid

            ajaxRequest.xmlResponse("Success")

Ext js 應用系列二:Page Grid

        End If        

Ext js 應用系列二:Page Grid

    End If

Ext js 應用系列二:Page Grid
Ext js 應用系列二:Page Grid

    Exit Sub

Ext js 應用系列二:Page Grid
Ext js 應用系列二:Page Grid

errHandle:

Ext js 應用系列二:Page Grid

    Call bbstkLogError(CurLocation, Err, Erl, Error)

Ext js 應用系列二:Page Grid

    ajaxRequest.xmlResponse("Failure:"+Error)

Ext js 應用系列二:Page Grid

End Sub

4、LS lib庫有一個專門處理AjaxRequest的類。