<ej:Grid ID="ProductGrid" ClientIDMode="Static" runat="server" AllowPaging="True" AllowFiltering="false" OnServerEditRow="EditEvents_ServerEditRow" OnServerAddRow="EditEvents_ServerAddRow" OnServerDeleteRow="EditEvents_ServerDeleteRow"> <ClientSideEvents ActionComplete="complete" RowSelected="selected" EndAdd="endAdd" EndDelete="endDelete" EndEdit="endEdit" /> ... <script type="text/javascript"> ... function selected(args) { var data = $('#<%= ProductGrid.ClientID %>').ejGrid("instance")._dataSource(); var grid = $('#<%= ProductGrid.ClientID %>').ejGrid("instance"); var record = args.data.Productcode; var detaildata = ej.DataManager(data).executeLocal(ej.Query().where("Productcode", ej.FilterOperators.equal, record, false)); var gridObj = $('#<%= MaterialGrid.ClientID %>').ejGrid("instance"); gridObj.dataSource(ej.DataManager(detaildata)); } </script> |
<ej:Column HeaderText=" " Template="true" TemplateID="#buttonTemplate" TextAlign="Center" Width="75" AllowFiltering="false"/>
$(function () {
$(".Details").ejButton({
click: function (e) {
},
});
}
$(function () { $(".Details").ejButton({ click: function (e) { var obj = $('#<%= ProductGrid.ClientID %>').data("ejGrid"); var record = obj.getSelectedRecords(); var gridObj = $('#<%= MaterialGrid.ClientID %>').ejGrid("instance"); if (gridObj.model.dataSource == null) gridObj.dataSource(record); else { gridObj.model.dataSource.push(record[0]); //push the dataSource object to the grid. gridObj.refreshContent(); } }) |
<ej:Grid ID="ProductGrid" ClientIDMode="Static" runat="server" AllowPaging="True" AllowFiltering="false" OnServerEditRow="EditEvents_ServerEditRow"
OnServerAddRow="EditEvents_ServerAddRow" OnServerDeleteRow="EditEvents_ServerDeleteRow">
<ClientSideEvents ActionComplete="complete" EndAdd="endAdd" EndDelete="endDelete" EndEdit="endEdit" DataBound="databound" />
...
function databound(args){
$(".Details").ejButton({
click: function (e) {
...
}
});
} |
<script type="text/template" id="materialtemplate">
...
<input id="Materialcode" name="Materialcode" value="{{: Materialcode}}"
...
<input id="Materialname" name="Materialname" value="{{:Materialname}}" class="e-field e-ejinputtext valid"
...
</table>
</script> |
protected void EditActionMaterial(string eventType, object record)
{
List<Materials> data = Session["MaterialDataSource"] as List<Materials>; //update the material grid records after selecting from client side.
Dictionary<string, object> KeyVal = record as Dictionary<string, object>;
if (eventType == "endEdit")
{
Materials value = new Materials();
foreach (KeyValuePair<string, object> keyval in KeyVal)
{
if (keyval.Key == "Materialcode")
{
...
}
}
}
Session["MaterialDataSource"] = data;
this.MaterialGrid.DataSource = data;
this.MaterialGrid.DataBind();
}
[Serializable]
public class Materials
{
public Materials()
{
}
public Materials(int Materialcode, string Materialname, int Productcode, string Productname)
{
this.Materialcode = Materialcode;
this.Materialname = Materialname;
this.Productname = Productname;
this.Productcode = Productcode;
}
public int Materialcode { get; set; }
public string Materialname { get; set; }
public int Productcode { get; set; }
public string Productname { get; set; }
} |
if (eventType == "endEdit")
{
Materials value = new Materials();
foreach (KeyValuePair<string, object> keyval in KeyVal)
{
if (keyval.Key == "Productcode")
{
value = data.Where(d => d.Productcode == (int)keyval.Value).FirstOrDefault();
value.Productcode = Convert.ToInt32(keyval.Value);
}
else if (keyval.Key == "Materialname")
value.Materialname = Convert.ToString(keyval.Value);
else if (keyval.Key == "Materialcode")
value.Materialcode = Convert.ToInt16(keyval.Value);
}
<asp:HiddenField ID="SelectRecords" ClientIDMode="Static" runat="server" /> <script type="text/javascript"> function OnCreate(args) { $(".Details").ejButton({ click: function (e) { var obj = $('#<%= ProductGrid.ClientID %>').data("ejGrid"); var record = obj.getSelectedRecords(); var gridObj = $('#<%= MaterialGrid.ClientID %>').ejGrid("instance"); $("#SelectRecords").val(JSON.stringify(record)); if (gridObj.model.dataSource == null) gridObj.dataSource(record); else { gridObj.model.dataSource.push(record[0]); gridObj.refreshContent(); } } }); } </script> protected void EditActionMaterial(string eventType, object record) { JavaScriptSerializer ser = new JavaScriptSerializer(); //get currentView List<Materials> sel = ser.Deserialize<List<Materials>>(this.SelectRecords.Value); . . . .. . Session["MaterialDataSource"] = data; this.MaterialGrid.DataSource = data; this.MaterialGrid.DataBind(); } |