zoukankan      html  css  js  c++  java
  • DevExpress MVC Gridview 把header caption 替换为 CheckBox (类似select all)

      

    效果图:

    Gridview. cshtml

    DevExpressGridHelper gridHelper = new DevExpressGridHelper(settings);
    gridHelper.AddCheckBoxColumnWithinHeader(Html, "AddToRpt", "Rpt", true, false, typeof(int), "1", "0", 50, false, true);
    DevExpressGridHelper.cs(完整的类在另一篇博文)
     public void CommonColumnSetting(MVCxGridViewColumn ao_Column, string as_FieldName, string as_Caption, int ai_Width, bool ab_Editable, bool ab_EditFormSettingsVisible, string as_DisplayFormatString = "", bool ab_IsRequired = false)
            {
                ao_Column.FieldName = as_FieldName;
                ao_Column.Caption = Utils.GetTranslation(as_Caption);
                ao_Column.HeaderStyle.Wrap = DefaultBoolean.True;
    
                if (!string.IsNullOrWhiteSpace(as_DisplayFormatString))
                {
                    ao_Column.PropertiesEdit.DisplayFormatString = as_DisplayFormatString;
                }
                if (ai_Width != 0)
                    ao_Column.Width = ai_Width;
                if (ab_EditFormSettingsVisible)
                    ao_Column.EditFormSettings.Visible = DevExpress.Utils.DefaultBoolean.True;
                else
                    ao_Column.EditFormSettings.Visible = DevExpress.Utils.DefaultBoolean.False;
    
                ao_Column.CellStyle.BackColor = System.Drawing.Color.Transparent;
                if (ab_IsRequired)
                    gs_MandatoryField += as_FieldName + ",";
    
                if (ab_Editable)
                {
                    gs_EditField += as_FieldName + ",";
                    ao_Column.CellStyle.BackColor = Utils.GetColor.EditableColor;
                }
    
                gs_Fields += as_FieldName + ",";
            }
    
    
    
            public void AddCheckBoxColumnWithinHeader(HtmlHelper helper, string as_FieldName, string as_Caption, object ao_ValueChecked, object ao_ValueUnchecked, Type ao_ValueType, string as_ValueCheckedString, string as_ValueUncheckedString, int ai_Width = 0, bool ab_Editable = false, bool ab_EditFormSettingsVisible = false, bool ab_IsRequired = false, string as_ValidationEvent = null)
            {
                this._Settings.Columns.Add(column =>
                {
                    this.CommonColumnSetting(column, as_FieldName, as_Caption, ai_Width, ab_Editable, ab_EditFormSettingsVisible, ab_IsRequired: ab_IsRequired);
    
                    column.SetHeaderTemplateContent(c =>
                    {
                        helper.DevExpress().CheckBox(chkSettings =>
                        {
                            chkSettings.Text = as_Caption;
                            chkSettings.Name = "chk" + this._Settings.Name + as_FieldName + "_SelectAll";
                            chkSettings.ControlStyle.Font.Underline = false;
                            chkSettings.Width = Unit.Percentage(100);
                            chkSettings.ControlStyle.HorizontalAlign = HorizontalAlign.Center;
                            chkSettings.Properties.ClientSideEvents.CheckedChanged = "function (s,e){ On" + chkSettings.Name + "(s,e);}";
                        }).Render();
                    });
                    column.ColumnType = MVCxGridViewColumnType.CheckBox;
                    var checkBoxProperties = column.PropertiesEdit as CheckBoxProperties;
                    checkBoxProperties.ValueChecked = ao_ValueChecked;
                    checkBoxProperties.ValueUnchecked = ao_ValueUnchecked;
                    checkBoxProperties.ValueType = ao_ValueType;
                    checkBoxProperties.ValueCheckedString = as_ValueCheckedString;
                    checkBoxProperties.ValueUncheckedString = as_ValueUncheckedString;
                    column.Settings.AllowSort = DefaultBoolean.False;
    
                });
            }
    

      

     JavaScript

    function OnchkModalDetailGridViewAddToRpt_SelectAll(s,e)
        {
            let lb_SelectAll = s.GetValue();
            let la_Indicies =  ModalDetailGridView.batchEditHelper.GetDataItemVisibleIndices();
            for( let i =0; i<la_Indicies.length; i++)
            {
                if(!ModalDetailGridView.batchEditApi.IsDeletedRow(la_Indicies[i]) && (ModalDetailGridView.batchEditApi.GetCellValue(la_Indicies[i], "Status")==1) )
                {
                    ModalDetailGridView.batchEditApi.SetCellValue(la_Indicies[i], "AddToRpt", (lb_SelectAll==true?1:0));
                }
            }
        }

     function OnModalDetailGridView_BatchStartEdit(s, e, as_Field) {
    
            gi_DetailRowIndex = e.visibleIndex;
            e.cancel = true;
            var ls_Status = ModalDetailGridView.batchEditApi.GetCellValue(e.visibleIndex, "Status");
        
            if (ls_Status == "0" && e.focusedColumn.fieldName =="AddToRpt") {
                e.cancel = false;
            }
        }    
    

      

      

  • 相关阅读:
    Atitit 趋势管理之道 attilax著
    Atitit 循环处理的新特性 for...else...
    Atitit 2017年的技术趋势与未来的大技术趋势
    atitit 用什么样的维度看问题.docx 如何了解 看待xxx
    atitit prj mnrs 项目中的几种经理角色.docx
    Atitit IT办公场所以及度假村以及网点以及租房点建设之道 attilax总结
    Atitit 工具选型的因素与方法 attilax总结
    Atitit.团队文化建设影响组织的的一些原理 法则 定理 效应 p826.v4
    Atiitt 管理方面的误区总结 attilax总结
    Atitit 未来趋势把控的书籍 attilax总结 v3
  • 原文地址:https://www.cnblogs.com/hesijian/p/12426886.html
Copyright © 2011-2022 走看看