public static MultiSelectBuilder CreateMultiSelect<T>(IHtmlHelper<T> Html, ScreenControlViewModel m)
{
var ctrl = Html.Kendo()
.MultiSelect()
.Name(m.ControlName)
.Placeholder(m.PlaceholderText)
.DataTextField(m.SelectedItemDisplayField)
.DataValueField(m.ValueFieldName)
.Filter(FilterType.Contains)
//.AutoBind(!string.IsNullOrEmpty(m.Value + "") ? true : false)
//.AutoBind(false)
// .HtmlAttributes(new { style = "width: 100%;" })
.DataSource(source =>
{
source.Read(read =>
{
read.Action(m.DataReadActionName, m.DataReadControllerName, m.RouteValues).Data(m.DataReadScriptFunctionName + "('" + m.ControlName + "')");
})
.ServerFiltering(true);
});
if (m.Value != null)
{
if (m.Value is IEnumerable)
ctrl.Value(m.Value as IEnumerable);
if (m.Value is string)
ctrl.Value(m.Value + "");
}
if (m.readOnly)
ctrl.HtmlAttributes(new { style = "width: 100%;", @readonly = "readonly" });
else
ctrl.HtmlAttributes(new { style = "width: 100%;" });
if (!string.IsNullOrWhiteSpace(m.ChangeScriptFunctionName))
ctrl.Events(e => e.Change(m.ChangeScriptFunctionName));
if (!string.IsNullOrWhiteSpace(m.SelectScriptFunctionName))
ctrl.Events(e => e.Select(m.SelectScriptFunctionName));
return ctrl;
}
public ActionResult GetDynamicControlDataForMCombobox(int screenControlQueryID, string text)
{
try
{
base.TraceLog("DataService GetDynamicControlDataForMCombobox", $"{SessionUser.Current.Username} -GetDynamicControlDataForMCombobox request");
//using (var db = AMS.CreateNewEntityObject())
{
ASelectionControlQueryTable tbl = ASelectionControlQueryTable.GetItem(_db, screenControlQueryID);
//add the where condition for the query
string whereCondition = "";
string OrderByQuery = "";
string[] filterFields = tbl.SearchFields.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
if (string.Compare(text, "Select Employee") == 0)
{
text = "";
}
Dictionary<string, object> parameters = new Dictionary<string, object>();
if ((!string.IsNullOrEmpty(text)) && (filterFields.Length > 0))
{
foreach (var f in filterFields)
{
var field = f.Trim();
if (whereCondition.Length > 0)
whereCondition += " OR ";
whereCondition += $"{field} like @{field}";
parameters.Add($"@{field}", $"%{text}%");
}
}
if (whereCondition.Length > 0)
whereCondition = " WHERE " + whereCondition;
if (!string.IsNullOrEmpty(tbl.OrderByQuery))
OrderByQuery = "" + tbl.OrderByQuery;
string finalQuery = $"SELECT TOP {maxRecordsPerRequest} * FROM ({tbl.Query}) A {whereCondition} {OrderByQuery}";
System.Data.DataTable dt = PMMSContext.GetDataTable(finalQuery, parameters, false);
return Json(dt);
}
public static DataTable GetDataTable(string procedureName, Dictionary<string, object> parameters, bool isProcedure = true)
{
using (SqlConnection cn = GetSqlConnection())
{
var cmd = cn.CreateCommand();
cmd.CommandText = procedureName;
if (isProcedure)
{
cmd.CommandType = CommandType.StoredProcedure;
}
else
{
cmd.CommandType = CommandType.Text;
}
cmd.CommandTimeout = CommandTimeout;
if (parameters != null)
{
foreach (string key in parameters.Keys)
{
if (key.StartsWith("@"))
cmd.Parameters.AddWithValue(key, parameters[key]);
else
cmd.Parameters.AddWithValue("@" + key, parameters[key]);
}
}
//if(procedureName.Contains("@WarehouseID"))
//{
// cmd.Parameters.AddWithValue("@WarehouseID" , SessionUserHelper.CurrentSessionUser.WarehouseID.ToString());
//}
SqlDataAdapter da = new SqlDataAdapter(cmd);
var ds = new DataTable();
da.Fill(ds);
return ds;
}
}
queries I am maintaining in backend . withoot linq query and load the data like that . when filter the details not filter working . if am used the json method its working filters. if am used datatable return values not working filter.
