2个grid联动问题

发布于 2020-03-04 00:20:54

2个Grid的联动,Grid的数据来自不同的表。

查看更多

关注者
0
被浏览
362
1 个回答
woneal
woneal 2020-03-04

这个很简单啊,在listVM里添加数据项,listVM里对应的View的Class里添加另一个grid对应字段,在efcore查询字段哪里添加需要的数据就行了。
比如我有个绩效分数的grid,同时想限制对应绩效月份和部门,这两个都在别的表里,那我首先在View这里加入我要的字段。

public class JiXiaoFenshu_View : JiXiaoFenshu
    {
        [Display(Name = "绩效动态")]
        public String JXDT_view { get; set; }
        [Display(Name = "姓名")]
        public String EmpName_view { get; set; }
        [Display(Name = "部门")]
        public string dpt { get; set; }
        [Display(Name = "绩效月份")]
        public string Jxyue { get; set; }


    }

然后再InitGridHeader这里进行初始化

 protected override IEnumerable<IGridColumn<JiXiaoFenshu_View>> InitGridHeader()
        {
            return new List<GridColumn<JiXiaoFenshu_View>>{
                this.MakeGridHeader(x => x.dpt),
                this.MakeGridHeader(x => x.Jxyue),
                this.MakeGridHeader(x => x.JXDT_view),
                this.MakeGridHeader(x => x.EmpName_view),
                this.MakeGridHeader(x => x.JxFenshu),
                this.MakeGridHeader(x => x.JxSalary),
                this.MakeGridHeader(x => x.isApproved),
                this.MakeGridHeaderAction(width: 200)
            };
        }

然后再getsearchquery这里添加需要的字段

var query = DC.Set<JiXiaoFenshu>()
            
             .CheckEqual(Searcher.EmployeeID, x => x.EmployeeID)
             .Select(x => new JiXiaoFenshu_View
             {
                 ID = x.ID,
                 dpt=x.JiXiaoDongTai.JXDepartment.EmpDepartmentName,
                 Jxyue=x.JiXiaoDongTai.JXyue.yearMonth,
                 JXDT_view = x.JiXiaoDongTai.JXDT,
                 EmpName_view = x.Employee.EmpName,
                 JxFenshu = x.JxFenshu,
                 JxSalary = x.JxSalary,
                 isApproved = x.isApproved,

             })

             .OrderBy(x => x.ID);
        return query;

撰写答案

请登录后再发布答案,点击登录

发布
问题

分享
好友

手机
浏览

扫码手机浏览