<Grid>
<ej:Grid ID="Grid1" AllowPaging="True"
runat="server">
<Columns>
. . .
</Columns>
<ClientSideEvents RecordClick="RecordClick" ActionComplete="ActionComplete"/> . . .
<EditSettings AllowEditOnDblClick="false" AllowEditing="True" AllowAdding="True" AllowDeleting="True" EditMode="InlineFormTemplate" InlineFormTemplateID="#template"></EditSettings>
</ej:Grid>
<Template>
<script type="text/template" id="template">
<b>Order Details</b>
<table cellspacing="10">
<tr>
<td style="text-align: right;">Order ID
</td>
<td style="text-align: left">
<input id="OrderID" name="OrderID" value="{{: OrderID}}" disabled="disabled"
class="e-field e-ejinputtext valid e-disable" style="text-align: right; width: 116px; height: 28px" />
</td>
<td style="text-align: right;">Employee ID
</td>
<td style="text-align: left">
<input id="EmployeeID" name="EmployeeID" value="{{:EmployeeID}}" class="e-field e-ejinputtext valid"
style="width: 116px; height: 28px; text-align: left!important" />
</td>
</tr>
<tr>
<td style="text-align: right;">FristName
</td>
<td style="text-align: left">
<input type="text" id="FristName" name=" FristName " value=" " />
</td>
</tr>
</table>
</script>
<RecordClick Event>
function RecordClick(args) {
emp = args.data.EmployeeID; // We can get the employeeID data while selecting the Grid
}
<ActionComplete>
function ActionComplete(e) {
if (e.requestType == "beginedit") { // Check the Condition
var columnCount = e.model.columns.length;
for (var k = 0; k < columnCount; k++) {
if (this.model.columns[k]["field"] == "EmployeeID")
{
var dataManager = ej.DataManager(this.model.columns[k]["dataSource"]).executeLocal(ej.Query().where("EmployeeID", "equal", emp));// Filter the datasource with selected employeeID value
var value = dataManager[0].FirstName;
$("#FirstName").val(value); //Update the data
}
}
}
} |
<GRID>
<ej:Grid ID="Grid1" AllowPaging="True"
EnableRowHover="true" AllowCellMerging="false"
AllowReordering="false" Locale="en-US" AllowMultiSorting="false"
AllowSelection="True" Selectiontype="Single"
runat="server">
<Columns>
. . .
</Columns>
<ClientSideEvents RecordClick="RecordClick" ActionComplete="ActionComplete"/>
. . .
</ej:Grid>
<Template for second datasource fields>
<script type="text/template" id="template">
<b>Order Details</b>
<table cellspacing="10">
<tr>
<td style="text-align: right;">Employee ID
</td>
<td style="text-align: left">
<input id="EmployeeID" name="EmployeeID" disabled="disabled" value="{{:EmployeeID}}"
class="e-field e-ejinputtext valid e-disable" style="width: 116px; height: 28px; text-align: left!important" />
</td>
<td style="text-align: right;">PostalCode
</td>
<td style="text-align: left">
<input id="PostalCode" name="PostalCode" value="" disabled="disabled"
class="e-field e-ejinputtext valid e-disable" style="text-align: right; width: 116px; height: 28px" />
</td>
</tr>
<tr>
<td style="text-align: right;">FirstName
</td>
<td style="text-align: left">
<input type="text" class="e-field e-ejinputtext valid e-disable" id="FirstName" name="FirstName" disabled="disabled" value="" />
</td>
<td style="text-align: right;">LastName
</td>
<td style="text-align: left">
<input id="LastName" name="LastName" value="" disabled="disabled"
class="e-field e-ejinputtext valid e-disable" style="text-align: right; width: 116px; height: 28px" />
</td>
</tr>
<tr>
<td style="text-align: right;">City
</td>
<td style="text-align: left">
<input type="text" class="e-field e-ejinputtext valid e-disable" id="City" disabled="disabled" name="City" value="" />
</td>
<td style="text-align: right;">Country
</td>
<td style="text-align: left">
<input type="text" class="e-field e-ejinputtext valid e-disable" id="Country" disabled="disabled" name="Country" value="" />
</td>
</tr>
</table>
</script>
<RECORD CLICK EVENT>
function RecordClick(args) {
var emp = args.data.EmployeeID; // We can get the employeeID data while selecting the Grid
dataSource2 = ej.DataManager(window.employeeView).executeLocal(ej.Query().where("EmployeeID", 'equal', emp)); //// get the filtered data from another datasource
}
<ActionComplete Event>
function ActionComplete(e) {
if (e.requestType == "beginedit") { // Check the Condition
var data = dataSource2[0]; $("#PostalCode").val(data.PostalCode); //Store the data into template fields with another datasource
$("#FirstName").val(data.FirstName); //Store the data into template fields with another datasource
$("#LastName").val(data.LastName); //Store the data into template fields with another datasource
$("#City").val(data.City); //Store the data into template fields with another datasource
$("#Country").val(data.Country); //Store the data into template fields with another datasource
}
} |
<GRID>
div class="frame ">
<div>
<ej:Grid ID="EmployeesGrid" runat="server" AllowPaging="true" DetailsTemplate="#tabGridContents">
<ClientSideEvents DetailsDataBound="detailGridData" />
<Columns>
. . .
</Columns>
<PageSettings PageSize=5></PageSettings>
</ej:Grid>
</div>
<Another Grid>
<ej:Grid ID="OrdersGrid" runat="server" AllowPaging="true">
<Columns>
. . .
</Columns>
</ej:Grid>
//Detailtemplate
<script id="tabGridContents" type="text/x-jsrender">
<div id="detailGrid{{:EmployeeID}}">
<b>Order Details</b>
<table cellspacing="10">
<tr>
<td style="text-align: right;">Employee ID
</td>
<td style="text-align: left">
<input class="EmployeeID" name="EmployeeID" disabled="disabled" value=""
style="width: 116px; height: 28px; text-align: left!important" />
</td>
<td style="text-align: right;">PostalCode
</td>
<td style="text-align: left">
<input class="PostalCode" name="PostalCode" value="" disabled="disabled"
style="text-align: right; width: 116px; height: 28px" />
</td>
</tr>
<tr>
<td style="text-align: right;">FirstName
</td>
<td style="text-align: left">
<input type="text" class="FirstName" name="FirstName" disabled="disabled" value="" />
</td>
<td style="text-align: right;">LastName
</td>
<td style="text-align: left">
<input class="LastName" name="LastName" value="" disabled="disabled"
style="text-align: right; width: 116px; height: 28px" />
</td>
</tr>
<tr>
<td style="text-align: right;">City
</td>
<td style="text-align: left">
<input type="text" class="City" disabled="disabled" name="City" value="" />
</td>
<td style="text-align: right;">Country
</td>
<td style="text-align: left">
<input type="text" class="Country" disabled="disabled" name="Country" value="" />
</td>
</tr>
</table>
</div>
</script>
<Detail Grid>
<script type="text/javascript">
function detailGridData(e) {
var filteredData = e.data["EmployeeID"];
var data = ej.DataManager(window.ordersView).executeLocal(ej.Query().where("EmployeeID", "equal", parseInt(filteredData), true)); // Bound the Grid with different data source
e.detailsElement.find("#detailGrid"+filteredData).ejGrid({
dataSource: data,
allowSelection: false,
columns: [
{ field: "EmployeeID", width: 90 },
{ field: "OrderID", isPrimaryKey: true, headerText: "Order ID", width: 80, textAlign: ej.TextAlign.Right },
{ field: "CustomerID", headerText: 'Customer ID', width: 80, textAlign: ej.TextAlign.Left },
{ field: "CompanyName", headerText: 'Company Name', width: 120, textAlign: ej.TextAlign.Left },
{ field: "ShipCity", headerText: 'City', width: 120, textAlign: ej.TextAlign.Left }
]
});
}
<Details data bound event>
function detailGridData(e) {
var emp = e.data.EmployeeID
var dataSource2 = ej.DataManager(window.employeeView).executeLocal(ej.Query().where("EmployeeID", 'equal', emp)); //// get the filtered data from another datasource
var data = dataSource2[0];
e.detailsElement.find(".EmployeeID").val(emp);
e.detailsElement.find(".PostalCode").val(data.PostalCode); //Store the data into template fields with another datasource
e.detailsElement.find(".FirstName").val(data.FirstName); //Store the data into template fields with another datasource
e.detailsElement.find(".LastName").val(data.LastName); //Store the data into template fields with another datasource
e.detailsElement.find(".City").val(data.City); //Store the data into template fields with another datasource
e.detailsElement.find(".Country").val(data.Country); //Store the data into template fields with another datasource
}
// render the another grid when select the record from master Grid
$(function () {
$('#<%= EmployeesGrid.ClientID %>').ejGrid({
selectedRowIndex: 0,
rowSelected: function (args) {
var employeeId = args.data.EmployeeID;
var detaildata = ej.DataManager(window.ordersView).executeLocal(ej.Query().where("EmployeeID", ej.FilterOperators.equal, employeeId, false).take(10));// bound the different data source
var gridObj = $('#<%= OrdersGrid.ClientID %>').ejGrid("instance");
gridObj.dataSource(ej.DataManager(detaildata.slice(0, 5)));
}
});
});
//Record Click event
function recordClick(e) {
var detailIcon = e.row.find(".e-detailrowcollapse").find(".e-icon");
this.expandCollapse(detailIcon);//expand the detail grid when click the record
} |