DevExPress控件 客户端常用方法

时间:2022-12-10 08:32:24

一、aspxmenu和aspxgridview组合

客户端:

function MenuItemClick(s, e) {
    //通过e.item.name来区别由Menu的哪一项来触发
    switch (e.item.name) {
        case "new":
            //新增操作
            grid.AddNewRow();
            break;
        case "edit":
            var index = grid.GetFocusedRowIndex();
            if (index != -1) {
                grid.StartEditRow(index);
            } else {
                alert('请选择要编辑的记录!');
            }
            //编辑操作
            break;
        case "delete":
            var key = grid.GetRowKey(grid.GetFocusedRowIndex());
            if (key != null && key != "") {
                if (window.confirm('你确定要删除这条记录吗?')) {
                    grid.PerformCallback("delete|" + key);
                }
            }
            //删除操作
            break;
        case "select":
            var key = grid.GetRowKey(grid.GetFocusedRowIndex());
            if (key != null && key != "") {
               grid.PerformCallback("select|" + key);
            }
            //删除操作
            break;
        case "refresh":
            grid.PerformCallback("refresh");
            //刷新操作
            break;
        case "export":
            grid.PerformCallback("export");
            alert('PerformCallback:export');
            //刷新操作
            break;
        case "selectall":
            grid.SelectAllRowsOnPage("true");
            alert('selectall');
            //全部选中当前页所有行
            break;
        case "selectallno":
            grid.SelectAllRowsOnPage("false");
            alert('selectallno');
            //全部选中当前页所有行
            break;
    }
}  
function gridrowselect(s, e) {
    var key = grid.GetRowKey(grid.GetFocusedRowIndex());
    if (key != null && key != "") {
       grid.PerformCallback("select|" + key);
    }
}
function EndCallback(s, e) {
    if (s.cp_msg) {
        alert(s.cp_msg);
        s.cp_msg = null;
    }
}
/*aspxtreeview ajax */
function trvofficeClick(s, e) {
    var filter = e.node, text;
    if (e.node.text=="分公司" || e.node.name=="root" || !e.node.parent){
        filter="%";}
        grid.ApplyFilter("科室 like '"+filter+"'");
}
服务端:
 Private Sub ASPxGridView1_CustomDataCallback(sender As Object, e As ASPxGridViewCustomDataCallbackEventArgs) Handles ASPxGridView1.CustomDataCallback
        '可用于前后台的数据传输和回调
        '调用客户端performCallBack方法时触发
        Dim grid As ASPxGridView
        grid = DirectCast(sender, ASPxGridView)

        If e.Parameters.Length <= 0 Then Return
        '分割符号,取决于前台performCallBack方法时触发时格式如
        '前台代码 grid.performcallback('edit|2')
        '前台代码 grid.performcallback('add')
        Dim strParames() As String = e.Parameters.ToString.Split("|")

        '    Dev控件约定,此处添加JSProperties的key,只能以 cp 为前缀。
        Select Case strParames(0).ToLower
            Case "delete"
                Dim id As String = strParames(1) '获取id
            Case "search"
                Dim keys As String = e.Parameters(1)
                grid.Selection.UnselectAll()
                For i As Integer = 0 To grid.VisibleRowCount - 1
                    If grid.GetRowValues(i, "Country") IsNot Nothing Then
                        If (grid.GetRowValues(i, "Country").ToString() = keys) Then
                            grid.Selection.SelectRow(i)
                        End If
                    End If
                Next

            Case "addnew"
                grid.AddNewRow()
            Case "edit"
                If e.Parameters.Length > 1 Then
                    grid.StartEdit(CInt(strParames(1)))
                End If
            Case "copy"
            Case "filter"
            Case "export"
                Dim strdir As String
                strdir = System.Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory)


        End Select

    End Sub