|
col.Field("Freight").HeaderText("Freight").TextAlign(TextAlign.Right).Priority(3).Width(75).Format("{0:C}").Add();
col.Field("ShipName").HeaderText("Ship Name").Width(110).Add();
col.Field("ShipCity").HeaderText("Ship City").Width(90).Priority(2).Add();
col.Template("#check").HeaderText("CheckBox").Width(50).Add();
})
.ClientSideEvents(e=>e.RecordClick("recordClick")))
</div> |
|
<script id="check" type="text/x-jsrender"> @*to render the checkbox in the Grid*@
<input id="{{:OrderID}}"type="checkbox"/> @*To set the unique id value*@
</script>
<script type="text/javascript">
function recordClick(args) {
if (args.columnName == "CheckBox" && $("#" + args.data.OrderID).is(":checked")) { @* ajax post will be called only when checkbox is clicked*@
var val = args.data;
$.ajax({
type: "POST",
url: "/Grid/DataSourceVentas2",
data: {
value: JSON.stringify(val) // pass the current rowData as the parameter
},
success: function (result) {
}
});
}
}
</script> |
|
public ActionResult DataSourceVentas2(string value)
{
var val = value; // retrun value in form of string
var value1 = Newtonsoft.Json.JsonConvert.DeserializeObject(value); // retrun value in form of object
return Json(value1,JsonRequestBehavior.AllowGet);
} |
|
|
Thank you for the reply.
I am loading the grid from a partial view.
.Columns(col =>
{
//col.Field("IsSelected").Type("checkbox").Width(20).Add();
col.Field("SerialNumber").HeaderText("Serial Number").Width(60).Add();
col.Template("#check").HeaderText("CheckBox").Width(50).Add();
})
.ClientSideEvents(e => e.RecordClick("recordClick")))
When I add the above click event to the grid columns, the grid no longer renders because I get the following error:
"GET http://localhost:8040/Jobcard/GetOpenJobcardsByModel?deviceModel=AFR2-HV-B3 500 (Internal Server Error)"
Neill
*Edit*
Looking at the code is my assumption correct that the ajax method is called each time a checkbox is checked? If this is the case then it is not what I am trying to achieve.
I want to be able to check any number of checkboxes, click a button and POST all the checked boxes data to my controller.
Neill
|
@(Html.EJ().Grid<object>("Grid")
.Datasource((IEnumerable<object>)ViewBag.data)
.AllowPaging()
.SelectionType(SelectionType.Multiple)
.Columns(col =>
{
...
})
.ClientSideEvents(eve => eve.Create("create").ActionComplete("complete").RecordClick("recordClick"))
)
...
<script type="text/javascript">
$(function () {
$("#btn").ejButton({
click: function (args) {
var grid = $("#Grid").ejGrid("instance");
var val = grid.getSelectedRecords(); //get the grid selected records
$.ajax({
type: "POST",
url: "/Home/DataSourceVentas2",
data: {
value: JSON.stringify(val) // pass the current rowData as the parameter
},
success: function (result) {
}
});
}
})
})
...
</script> |
Thank you,
With the sample I have managed to my code working.
I have 2 questions though.
1. When I use the "Select All" checkbox in the grid header, the first row checkbox and the checkbox in the header is not selected. All other rows are selected.
2. On my submit button, I am using custom classes for the button look. After the grid is rendered the button no longer looks the way it should.
It should look like this:
But instead it looks like this:
It is as if the CSS class is being overwritten. I am using bootstrap for the button.
Neill
*EDIT*
As a side note I'm not sure if the problem is because in my ajax success, I have to call ej.widget.init($('#OpenJobCards')) or else my grid does not render.
i see if the supplied sample that that call is not neccessary?
*EDIT AGAIN*
I created a brand new project from the Syncfusion Template and the same problem occurs.
Please help me sort this out ASAP.
Neill
| .Columns(col => { col.Type("checkbox").Width(50).Add(); col.Field("OrderID").HeaderText("OrderID").IsPrimaryKey(true).Add(); col.Field("CustomerID").HeaderText("Customer ID").Add(); |
| |
| .ClientSideEvents(eve => eve.Create("create").ActionComplete("complete").RowSelecting("rowselect")) function rowselect(args) { var flag = false; if ($(args.target).hasClass("e-checkselectall")) { if (!($(args.row).find("input").is(":checked"))) // to cancel the selection on unchecking the box args.cancel = true; // to cancel the selecting of all reord in grid flag = true; } if (flag == true) { if (!($(args.row).find("input").is(":checked"))) { var check = $("#Grid").ejGrid("instance"); check.selectRows(0, this.model.currentViewData.length - 1); // to select the row based on index, } } } |
| <style type="text/css"> .violet{ background-color:blueviolet !important; } </style> |
Goo day,
Apologies, I did indeed upgrade to the latest version.
With the code you have provided it is working perfectly.
Also I changed this line:
$("#btn").ejButton({
to not use ejButton, but a normal click event:
$("#btn").off().on("click", function() {
and this no longer overwrites the CSS class and my button looks the way it should.
Many thanks for your continued support.
Neill