IT俱乐部 ASP.NET asp.net core使用DevExtreme20将int列转为checkbox方法示例

asp.net core使用DevExtreme20将int列转为checkbox方法示例

后端设置扩展方法

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
public static void SetNumCheckBox(this DataGridColumnBuilder builder)
{
    _ = builder.CellTemplate(new JS("CheckBoxCellTemplate"))
        .EditCellTemplate(new JS("CheckBoxEditorTemplate"))
        .Lookup(lookup => lookup.DataSource(new object[] {
                new {
                    label = "是",
                    value = 1,
                },
                new {
                    label = "否",
                    value = 0,
                },
    }).DisplayExpr("label").ValueExpr("value"));
}

前端添加单元格和编辑代码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
const getNewDomId = (function () {
  let id = 1;
  return function () {
    return id++;
  };
})();
function CheckBoxEditorTemplate(el, e) {
  var domId = 'grid_cell_' + getNewDomId();
  el.html(`<div id="${domId}"></div>`);
  new Vue({
    el: '#' + domId,
    template: ``,
    data: {
      state: e.value === 1,
    },
    methods: {
      onChange(value) {
        e.setValue(value ? 1 : 0);
      },
    },
  });
}
function CheckBoxCellTemplate(container, options) {
  container.html(
    `<div class="dx-checkbox-container ${
      options.value === 1 ? 'dx-checkbox-checked' : ''
    }"><span class="dx-checkbox-icon"></span></div>`
  );
}

以上就是asp.net core使用DevExtreme20将int列转为checkbox方法示例的详细内容,更多关于asp.net core将int列转为checkbox的资料请关注IT俱乐部其它相关文章!

本文收集自网络,不代表IT俱乐部立场,转载请注明出处。https://www.2it.club/code/asp-net/9553.html
上一篇
下一篇
联系我们

联系我们

在线咨询: QQ交谈

邮箱: 1120393934@qq.com

工作时间:周一至周五,9:00-17:30,节假日休息

关注微信
微信扫一扫关注我们

微信扫一扫关注我们

返回顶部