-
Notifications
You must be signed in to change notification settings - Fork 55
/
ColumnVisibilityDemo.cshtml
115 lines (94 loc) · 3.74 KB
/
ColumnVisibilityDemo.cshtml
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
@using MVCGrid.Web
@{
ViewBag.Title = "Column Visibility";
}
@section head{
<style type="text/css">
.sortable ul{
list-style-type:none;
list-style:none;
}
.sortable li{
list-style: none;
height: 40px;
}
.handle{
cursor: move;
}
li.sortable-placeholder {
border: 1px dashed #CCC;
background: none;
}
</style>
}
@section scripts{
<script src="~/Scripts/jquery.sortable.min.js"></script>
<script type="text/javascript">
$(function () {
var html = '';
var colVis = MVCGrid.getColumnVisibility('ColumnVisibilityGrid');
html += '<ul class="sortable" style="padding-left:0;">';
@*<div class="input-group">
<span class="input-group-addon" id="basic-addon1">@</span>
<input type="text" class="form-control" placeholder="Username" aria-describedby="basic-addon1">
</div>*@
$.each(colVis, function (colName, col) {
html += '<li draggable="true">';
html += '<div class="input-group">';
html += '<span class="input-group-addon handle">::</span>';
html += '<label class="form-control">';
html += '<input type="checkbox" name="cols" value="' + colName + '"';
if (col.visible) {
html += ' checked';
}
if (!col.allow) {
html += ' disabled';
}
html += '>';
html += col.headerText;
html += "</label>";
html += '</div>';
html += '</li>';
});
html += '</ul>';
$('#colVisOptions').html(html);
$('.sortable').sortable({
handle: '.handle'
});
$('#colVisUpdateButton').click(function () {
var jsonData = {};
$("input:checkbox[name='cols']:checked").each(function () {
var columnName = $(this).val();
jsonData[columnName] = true;
});
MVCGrid.setColumnVisibility('ColumnVisibilityGrid', jsonData);
$('#myModal').modal('hide');
});
});
</script>
}
<h2>@ViewBag.Title</h2>
<p>Create your own UI to show/hide or re-order columns based on the data from the client-side api function <code>MVCGrid.getColumnVisibility</code>, and then use the <code>MVCGrid.setColumnVisibility</code> to update the grid.</p>
<p>In the column definition, set <code>Visible</code> to false and set <code>AllowChangeVisibility</code> to true to allow the column to be displayed.</p>
<button type="button" class="btn btn-primary btn-lg" data-toggle="modal" data-target="#myModal">
Show/Hide Fields
</button>
@Html.MVCGrid("ColumnVisibilityGrid")
<!-- Modal -->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h4 class="modal-title" id="myModalLabel">Choose Fields</h4>
</div>
<div class="modal-body">
<div id="colVisOptions"></div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
<button type="button" id="colVisUpdateButton" class="btn btn-primary">Update</button>
</div>
</div>
</div>
</div>