Ext.Net中CheckboxSelectionModel的动态隐藏(显示),一定条件下的隐藏(不让选择),获得多选栏位的信息,及后台控件的动态创建

(1) Ext.Net 中CheckboxSelectionModel在一定的条件下隐藏特定的row

<head id="Head1" runat="server">
    <title></title>
    <script  type="text/javascript">
           var MyCheckBox = function (v, p, record) {                //固定格式,不变
            if (record.data.SPECVER <4) {     //红色的字体为栏位名称(type= int)
                return "";
            }

            return '<div class="x-grid3-row-checker">';      //固定格式,不变
        };
    </script>   
</head>

并在下面的代码添加CustomConfig,Listeners属性  :

         <SelectionModel>
                <ext:CheckboxSelectionModel ID="CheckboxSelectionModel1"   runat="server">   //生成CheckBox
                    <CustomConfig>          
                          <ext:ConfigItem Name="renderer" Value="MyCheckBox" Mode="Raw" />        //javascript Function 名称
                     </CustomConfig>
                     <Listeners>
                           <BeforeRowSelect Handler="return record.data.SPECVER>=4;" />         //栏位名称,需要变动
                     </Listeners>
                </ext:CheckboxSelectionModel>                                                           
          </SelectionModel>

 

(2 )Ext.Net 中动态的隐藏(Hidden属性)CheckBox  (CheckboxSelectionModel ):

               

protected void btnQueryHistory_Click(object sender, Ext.Net.DirectEventArgs e)

{

       GridPanel. ColumnModel.SetHidden(0,true);          //(红色的)为GridPanel 名称   ,(绿色的)为要隐藏的栏位

}

 (3)Ext.Net中获得被多选中的row :

        1.))集中批次处理:

              RowSelectionModel lv_RowSelected = this.gpControlInfo.SelectionModel.Primary as RowSelectionModel;
              if (lv_RowSelected.SelectedRows.Count > 0)

             {

                     string sysIDS = "";
                     foreach (SelectedRow row in sm.SelectedRows)
                    {
                          sysIDS += row.RecordID + ";";              //RecordID的设置
                    }

              }
              lv_RowSelected.ClearSelections();     //需要清空所有,否则,下次没有选中任何的时候,SelectedRows.Count 还是为上次的值

           RecordID的设置,在Store的代码中添加(红色的部分):

          <ext:Store ID="stoControlInfo" runat="server" GroupDir="ASC">
                <Reader>               
                    <ext:JsonReader IDProperty ="FORMSYSID">            //  为RecordID的值,根据需要相应的更改           
                    </ext:JsonReader>                
                </Reader>
                <AutoLoadParams>
                    <ext:Parameter Name="start" Mode="Raw" Value="0">
                    </ext:Parameter>
                    <ext:Parameter Name="limit" Mode="Raw" Value="15">
                    </ext:Parameter>
                </AutoLoadParams>
         </ext:Store>

     2.))  单个的处理:

         <ext:Button 
                  ID="" 
                  runat="" 
                  Text="" 
                  Icon=""                                                    
                  X ="" 
                  Y ="" >

                 <DirectEvents> 
                        <Click OnEvent="btnActivateForm_Click">                 //后台Button事件 
                              <ExtraParams>     //添加如下代码,gpControlInfo为GridPanel的ID
                                    <ext:Parameter Name="Values" Value="Ext.encode(#{gpControlInfo}.getRowsValues({selectedOnly:true}))" Mode="Raw" />
                              </ExtraParams>  
                         </Click>                                     
                  </DirectEvents>
        </ext:Button>

       后台的处理:

          string json = e.ExtraParams["Values"];

          Dictionary<string, string>[] lv_Row = JSON.Deserialize<Dictionary<string, string>[]>(v_Json);
            foreach (Dictionary<string, string> row in lv_Row)
            {
                foreach (KeyValuePair<string, string> keyvaluePaire in row)
                {

                    //可以取得所有的栏位及栏位值,

                   //也可以取得想要的(相对应的)
                    if (keyvaluePaire.Key == "SPECNO")
                    {
                        pv_StrSpecNO = keyvaluePaire.Value;
                    }
                    else if (keyvaluePaire.Key == "SPECVER")
                    {
                        pv_StrSpecVer = keyvaluePaire.Value;
                    }
                }

            }

(4)Ext.Net后台动态实现GridPanel栏位的添加:

            this.stoControlInfo.AddField(new RecordField("SYSID", RecordFieldType.String));
            this.stoControlInfo.AddField(new RecordField("FORMID", RecordFieldType.String));
           

            this.gpControlInfo.ColumnModel.Columns.Add(new Column { Header = "SYSID_Show", DataIndex = "SYSID", Width = 10 });
            this.gpControlInfo.ColumnModel.Columns.Add(new Column { Header = "FORMID_Show", DataIndex = "FORMID", Width = 130 });

 

        DataIndex必须和RecordField的相同(如红色的),要不然有栏位显示,但是下面没有数据的哦!

 

 

    注:以上经过测试是正确的,请根据自己的需要做出变通,不对的地方或者是还有好的方法请告知,不胜感激!

    另外:(1)一个好的Ext.Net基础学习网站是:www.Ext.Net,有各控件的实例实现

              (2)相关知识查找可以在官网(www.Ext.Net)中的右上角的"Search“框中进行查找,比在Baidu能查到更多的相关技术及实现!查找的是英文版的哦!

posted @ 2011-12-23 09:49  zp_Alex  阅读(3043)  评论(1编辑  收藏  举报