• 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;
            }
        }    
    

      

      

  • 相关阅读:
    阿里云:面向5G时代的物联网无线连接服务
    走近科学,探究阿里闲鱼团队通过数据提升Flutter体验的真相
    Redis 5.0新功能介绍
    阿里云发布 Redis 5.0 缓存服务:全新 Stream 数据类型带来不一样缓存体验
    荣获“5G MEC优秀商用案例奖”,阿里云边缘计算发力新零售
    阿里云亮相2019联通合作伙伴大会,边缘计算等3款云产品助力5G时代产业数字化转型
    noip2014 寻找道路
    noip2014 无线网络发射器选址
    noip2014 联合权值
    noip2013 华容道
  • 原文地址:https://www.cnblogs.com/hesijian/p/12426886.html
Copyright © 2020-2023  润新知