<ej:TreeGrid ID="TreeGridcontainer" runat="server"
ShowColumnChooser="true"
ShowColumnOptions="true">
//..
</ej:TreeGrid>
<script type="text/javascript">
function clickme(args) {
var treeObj = $("#TreeGridcontainer").data("ejTreeGrid"),
columns = $.extend([], treeObj.model.columns);
columns.push(
{ field: "column2", headerText: "New column 1", editType: "numericedit", width: "60" }
//..
);
treeObj.setModel({ "columns": columns });
}
</script> |
protected void Page_Load(object sender, EventArgs e)
{
this.TreeGridcontainer.DataSource = GetDataSource();
this.TreeGridcontainer.Columns = GetColumns();
this.TreeGridcontainer.DataBind();
} |
using Syncfusion.JavaScript.Models;
protected void Page_Load(object sender, EventArgs e)
{
this.TreeGridcontainer.DataSource = GetDataSource();
this.TreeGridcontainer.Model.Columns = GetColumns();
this.TreeGridcontainer.DataBind();
}
private List<TreeGridColumn> GetColumns()
{
List<TreeGridColumn> list = new List<TreeGridColumn>();
SqlConnection con = new SqlConnection(WebConfigurationManager.ConnectionStrings["SelfReferenceConnectionString"].ConnectionString);//connectionString
con.Open();
using (con)
{
using (var command = con.CreateCommand())
{
command.CommandText = "SELECT *FROM columnTree";
using (var reader = command.ExecuteReader())
{
var indexOfCol1 = reader.GetOrdinal("Field");
var indexOfCol2 = reader.GetOrdinal("HeaderText");
var indexOfCol3 = reader.GetOrdinal("Width");
var indexOfCol4 = reader.GetOrdinal("AllowEditing");
var indexOfCol5 = reader.GetOrdinal("AllowFiltering");
var indexOfCol6 = reader.GetOrdinal("AllowFreezing");
var indexOfCol7 = reader.GetOrdinal("TemplateID");
var indexOfCol8 = reader.GetOrdinal("IsTemplateColumn");
while (reader.Read())
{
TreeGridColumn obj = new TreeGridColumn();
obj.Field = reader.GetValue(indexOfCol1).ToString();
obj.HeaderText = reader.GetValue(indexOfCol2).ToString();
if (reader.GetValue(indexOfCol3).ToString() != "")
obj.Width = Convert.ToInt16(reader.GetValue(indexOfCol3));
if (reader.GetValue(indexOfCol4).ToString() != "")
obj.AllowEditing = Convert.ToBoolean(reader.GetValue(indexOfCol4));
if (reader.GetValue(indexOfCol5).ToString() != "")
obj.AllowFiltering = Convert.ToBoolean(reader.GetValue(indexOfCol5));
if (reader.GetValue(indexOfCol6).ToString() != "")
obj.AllowFreezing = Convert.ToBoolean(reader.GetValue(indexOfCol6));
obj.TemplateID = reader.GetValue(indexOfCol7).ToString();
if (reader.GetValue(indexOfCol8).ToString() != "")
obj.IsTemplateColumn = Convert.ToBoolean(reader.GetValue(indexOfCol8));
list.Add(obj);
}
reader.Close();
}
}
con.Close();
}
return list;
} |
[aspx.cs]
public void Add(TreeColumn Task)
{
string cmdString = "INSERT INTO columnTree ([Field],[HeaderText],[AllowEditing],[AllowFiltering],[AllowFreezing],[IsTemplateColumn],[ShowInColumnChooser],[TemplateID],[Width])" + "VALUES(@Field,@HeaderText,@AllowEditing,@AllowFiltering,@AllowFreezing,@IsTemplateColumn,@ShowInColumnChooser,@TemplateID,@Width)";
SqlConnection con = new SqlConnection(WebConfigurationManager.ConnectionStrings["SelfReferenceConnectionString"].ConnectionString);//connectionString
con.Open();
using (SqlCommand sqlCommand = new SqlCommand(cmdString, con))
{
sqlCommand.Parameters.AddWithValue("@Field", Task.Field).Value = Task.Field == null ? "" : Task.Field;
sqlCommand.Parameters.AddWithValue("@HeaderText", Task.HeaderText).Value = Task.HeaderText == null ? "" : Task.HeaderText;
sqlCommand.Parameters.AddWithValue("@AllowEditing", Task.AllowEditing).Value = Task.AllowEditing == null ? false : Task.AllowEditing;
sqlCommand.Parameters.AddWithValue("@AllowFiltering", Task.AllowFiltering).Value = Task.AllowFiltering == null ? false : Task.AllowFiltering;
sqlCommand.Parameters.AddWithValue("@AllowFreezing", Task.AllowFreezing).Value = Task.AllowFreezing == null ? false : Task.AllowFreezing;
sqlCommand.Parameters.AddWithValue("@IsTemplateColumn", Task.IsTemplateColumn).Value = Task.IsTemplateColumn == null ? false : Task.IsTemplateColumn;
sqlCommand.Parameters.AddWithValue("@ShowInColumnChooser", Task.ShowInColumnChooser).Value = Task.ShowInColumnChooser == null ? false : Task.ShowInColumnChooser;
sqlCommand.Parameters.AddWithValue("@TemplateID", Task.TemplateID).Value = Task.TemplateID == null ? "" : Task.TemplateID;
sqlCommand.Parameters.AddWithValue("@Width", Task.Width).Value = Task.Width == null ? 40 : Task.Width; ;
int test = sqlCommand.ExecuteNonQuery();
}
con.Close();
}
[WebMethod]
public static void AddIt(TreeColumn record)
{
TreeGridSample sample = new TreeGridSample();
sample.Add(record);
}
[aspx]
function clickme(args) {
var treeObj = $("#TreeGridcontainer").data("ejTreeGrid"),
columns = $.extend([], treeObj.model.columns),
updatedData = {
field: "column2", headerText: "New column 1", editType: "numericedit", width: "60"
};
columns.push(updatedData);
treeObj.setModel({ "columns": columns });
PageMethods.AddIt(updatedData);
}
function ActionComplete(args) {
// args.insertIndex
if (args.requestType == "insertColumn")
PageMethods.AddIt(args.columnObject);
} |