Hi Neeraj,
Sorry for the delay to get back you.
We are glad to let you know that we have created sample for
your requirement and the same can be downloaded from the following location.
Sample Location: http://www.syncfusion.com/downloads/support/directtrac/general/Samplec1-908437433.zip
In the above sample, We have created two dropdown list and
one button. On the first dropdown “change” event, we have retrieved column
list using “ajax post” and then we have updated second dropdown list in ajax
success using “setModel” of
Dropdown. Please refer the following code snippets to achieve your requirement
function change(arg) {
. . . . . . . . . . $.ajax({
url: "ColumnChooser.aspx/GetData", .
. . . . . success: function (data) {
var temp
= $("#DropDownList2").ejDropDownList("instance");
temp.setModel({ dataSource: data.d,
showCheckbox: true }); } }); } public static object GetData(string table) { . . .
. . . . . . . var columnName = GetColumns(table); return columnName; } |
We have selected the
required columns from the second dropdown. Then on button “click” event we have retrieved
corresponding data from server-side based on dropdown values using ajax post.
On that ajax success we have updated
Grid datasource using “dataSource” method
of Grid. Please refer the following code snippets to achieve your requirement.
function onClick(arg) { . . .
. . . . . $.ajax({
url: "ColumnChooser.aspx/getRecords", .
. . . . . success: function (data) {
. . . . . . . .
$("#FlatGrid").ejGrid({dataSource: query });
} }); } public static IEnumerable
getRecords(string table) { IEnumerable
dataSource =null; if (table == "Employees")
dataSource = new NorthwindDataContext().EmployeeViews.ToList(); if (table == "Orders")
dataSource = new NorthwindDataContext().OrdersViews.ToList(); return dataSource; } |
Please let us know if
you have any queries. We are happy to assist you.
Regards,
Saravanan.A
Hi Neeraj Purohit,
We deeply regret for the inconvenience caused and please ignore the previous update.
We have created a simple grid sample in which the grid datasource can be rendered based on the dropdown values and the same can be downloaded from the below location.
Sample Location: http://www.syncfusion.com/downloads/support/directtrac/general/DataBinding-Forms741345001.zip
In the above sample, the grid is initially loaded with the data from Orders table. And there are two dropdownlist available at the page in which one drop down list contains table names. The second dropdownlist will loaded with the corresponding column names available in the table selected in first dropdownlist. The second dropdownlist will be updated with the column names from server based on the value selected in the first dropdownlist in the change event as follows.
<div class="col-md-3" style="margin-top: 10px"> <label>Select Columns</label> <ej:DropDownList ID="drop1" runat="server" ClientSideOnChange="getColumns"> //Table Dropdownlist <Items> <ej:DropDownListItem Text="Orders" Value="Orders" /> <ej:DropDownListItem Text="Employees" Value="Employees" /> </Items> </ej:DropDownList> <br /> <label>Select Table</label> <ej:DropDownList ID="drop2" runat="server" ShowCheckbox="true"> //Column dropdownlist </ej:DropDownList> <br /> <br /> <ej:Button ID="done" runat="server" Type="Button" Text="Done" Size="Normal" ShowRoundedCorner="true" ClientSideOnClick="bindData"> </ej:Button> </div>
<script> function getColumns(args) { var val = this.getSelectedValue();//get table name $.ajax({ url: "Default.aspx/getColumns", type: "POST", contentType: "application/json; charset=utf-8", dataType: "json", data: JSON.stringify({ table: val }), success: function (data) { var drop2 = $("#drop2").ejDropDownList("instance"); $("#drop2").ejDropDownList({ dataSource: data.d, showCheckbox: true }); //binding the column names from the server } }); }
function bindData(args) { //ejButton onclick event var cols = $("#drop2").ejDropDownList("model.value"); //get selected column values var table = $("#drop1").ejDropDownList("getSelectedValue"); //get table name $.ajax({ url: "Default.aspx/getRecords", type: "POST", contentType: "application/json; charset=utf-8", dataType: "json", data: JSON.stringify({ table: table }), success: function (data) { $("#OrdersGrid").ejGrid("destroy"); // destroy grid $("#OrdersGrid").ejGrid({ dataSource: data.d, query: ej.Query().select(cols.split(",")), allowPaging: true }); //re-rendering grid with new data from server } }); } </script>
|
We have returned the column names and records from the server using the webmethod and it is as follows.
[System.Web.Services.WebMethod] // Return column names based on table public static IEnumerable getColumns(string table) { var model = new AttributeMappingSource().GetModel(typeof(NorthwindDataContext)); List<string> cols = new List<string>(); foreach (var mt in model.GetTables()) { if (mt.TableName == "dbo." + table) { foreach (var dm in mt.RowType.DataMembers) { cols.Add(dm.MappedName.ToString()); } } } return cols; }
[System.Web.Services.WebMethod] //Return records public static object getRecords(string table){ if(table == "Employees") return new NorthwindDataContext().EmployeeViews.ToList(); else if(table == "Orders") return new NorthwindDataContext().OrdersViews.Skip(0).Take(100).ToList(); return "Table not found"; }
|
The output of the above provide sample will look like follows.
Please let us know if you have any queries.
Regards,
Madhu Sudhanan. P
Hi Neeraj,
The sample provided in the previous update is created using Essential Studio Volume 3, 2014 (12.3.0.36). From the attached screenshot, we suspect that you are using different version and hence the error occurred. Also we have analyzed your requirement and we need to create custom sample to achieve your requirement and so we suggest you to create incident with details such as Essential Studio version you are using and your requirement details.
Please let us know if you have any queries.
Regards,
Madhu Sudhanan. P
Hi Madhu Sudhanan P,
As you are saying I will create a incident for the issue I am facing but as per my understanding there is no need to add my Custom requirements into that incident because I always mention my requirements in Forum so please provide me a sample as per our requirements.
Thanks
Neeraj Purohit
Hi Neeraj,
Sorry for the inconvenience caused.
Normally we will provide immediate solutions alone in forum. But your requirement requires more analysis and work. Hence we suggested you to create incident, so that we can achieve your requirement through custom sample. And also we noticed that you have created incident #132023 which is currently in sales pending, so please provide your requirements in that incident for better follow up.
Please let us know if you have any queries.
Regards,
Madhu Sudhanan. P
Hi Neeraj,
Thanks for your update.
We will wait to hear from you. Please follow-up the incident #132023 for further details about your query.
Please let us know if you have any concerns.
Regards,
Ajith R