<asp:Content runat="server" ID="BodyContent" ContentPlaceHolderID="MainContent">
<ej:Button runat='server' Type="Button" Text="getRecords" ClientSideOnClick="onClick" />
<ej:Grid id="FlatGrid" ClientIDMode="Static" runat='server' AllowPaging="true">
<ClientSideEvents RowSelected="rowselected" DataBound="databound" />
<Columns>
<ej:Column Type="checkbox" />
<ej:Column Field="OrderID" HeaderText="Order ID" Type="number" IsPrimaryKey="True" />
..
</Columns>
</ej:Grid>
<script>
window.records = [];
..
function rowselected(args) {
if ($(args.target).prop('checked') == false)
window.records.push(args.data);
else if ($(args.target).prop('checked')) {
for (var i = 0; i < window.records.length; i++) {
if (window.records[i].OrderID == args.data.OrderID) {
window.records.splice(i, 1);
break;
}
}
}
}
function onClick(args){
var obj = $("#FlatGrid").ejGrid("instance");
console.log(window.records);
}
</script>
</asp:Content>
|
<input type='button' id="btn">
<asp:Content runat="server" ID="BodyContent" ContentPlaceHolderID="MainContent">
<ej:Grid id="FlatGrid" ClientIDMode="Static" runat='server' AllowPaging="true">
<ClientSideEvents RowSelected="rowselected" DataBound="databound" />
<Columns>
<ej:Column Type="checkbox" />
..
</Columns>
</ej:Grid>
<script>
window.records = [];
function databound(args) {
//to handle the header checkbox selection
//works only for local dataSource
$('.e-checkselectall').click(function () {
if (!$(this).is(':checked'))
window.records = [];
else {
window.records = $("#FlatGrid").ejGrid("model.dataSource");
}
});
}
</script>
</asp:Content> |
function myFunc() {
var grid = $("#Grid").ejGrid("instance");
var checkeddata = [];
...
$.ajax({
type: "POST",
url: "/Home/Data",
success: function (result) {
var gridObj = $("#Grid").data("ejGrid");
var data= result;
for (i = 0; i < data.length; i++) {
var check = data[i].Verified;
if (check == true) {
checkeddata.push(data[i]);
}
}
alert("Checkbox data length :" + checkeddata.length);
},
});
}
</script> |
Hi Danferd,
When using remote data in grid it is processed based on demand loading. So we cannot get the whole data from grid.model.dataSource and we can able to retrieve only the current page data. As per your requirement you have get the checkbox details from whole grid data so to retrieve the whole data in button click we suggest you to pass the external AJAX post as like below.Refer the code example.
function myFunc() {var grid = $("#Grid").ejGrid("instance");var checkeddata = [];...$.ajax({type: "POST",url: "/Home/Data",success: function (result) {var gridObj = $("#Grid").data("ejGrid");var data= result;for (i = 0; i < data.length; i++) {var check = data[i].Verified;if (check == true) {checkeddata.push(data[i]);}}alert("Checkbox data length :" + checkeddata.length);},});}</script>Note: Since you have also performing CRUD operations in grid so we need to pass the external AJAX post to retrieve the whole data
Please let us know if you need further assistance.
Regards,Jayaprakash K.
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
Dim myConnection As SqlConnection = New SqlConnection(ConfigurationManager.ConnectionStrings("NORTHWNDConnectionString").ToString())
Dim dt As DataTable = New DataTable("Orders")
Dim take As SqlCommand = New SqlCommand("SELECT checkbox FROM Orders WHERE IF (@CheckStatus IS FALSE) DO SOMETHING ElSEIF (@CheckStatus IS TRUE), con);", SqlDataAdapter, __InlineAssignHelper(da, New SqlDataAdapter(take)))
Dim dt As DataTable = New DataTable()
da.Fill(dt)
con.Close()
Return dt.Rows(0)("checkbox").ToString()
End Sub |