I am trying pass parameter to the Kendo grid.It does pass parameter if its integer "100" and works perfect,but doesn't fire event if its ZZ001.can anyone help?
My code is as below:
@(Html.Kendo().Grid<orderlineview>()
.Name("OrderLineGrid")
.Columns(columns =>
{
columns.Bound(p => p.StockCode).Title("Stock Code").Width(250);
columns.Bound(p => p.OrderLineDescription).Title("Description");
columns.Bound(p => p.Quantity).HtmlAttributes(new { style = "text-align:right" });
columns.Bound(p => p.UnitPrice).Format("{0:c}").HtmlAttributes(new { style = "text-align:right" });
columns.Bound(p => p.DiscountPercentage).Title("Disc %").Width(70).HtmlAttributes(new { style = "text-align:right" });
columns.Bound(p => p.DiscountAmount).Title("Discount ").Format("{0:c}").HtmlAttributes(new { style = "text-align:right" });
columns.Bound(p => p.TaxRate).HtmlAttributes(new { style = "text-align:right" });
columns.Bound(p => p.TaxAmount).Title("Tax Amount").Format("{0:c}").HtmlAttributes(new { style = "text-align:right" });
columns.Bound(p => p.TotalPrice).Format("{0:c}").HtmlAttributes(new { style = "text-align:right" });
columns.Command(command =>
{
command.Edit().UpdateText(" ").CancelText(" ");
command.Destroy();
}).Width(170);
columns.Bound("").ClientTemplate("<input type='button' onclick='OpenItemhistoryPopup(#=StockCode #)' value='History' ></input>");
})
.ToolBar(toolbar => toolbar.Create())
.Editable(editable => editable.Mode(GridEditMode.InLine)
)
.HtmlAttributes(new { style = "height:430px; overflow-y:scroll" })
.Events(ev=>ev.Edit("EditGrid")
.Save("Rearrange")
)
.DataSource(dataSource => dataSource
.Ajax()
.Events(e => e.RequestEnd("onRequestEnd"))
.Model(model => model.Id(p => p.OrderLineId))
.Create(update => update.Action("OrderLineCreate", "Order"))
.Read(read => read.Action("GetAllOrderLines", "Order"))
.Update(update => update.Action("OrderLineUpdate", "Order"))
.Destroy(update => update.Action("OrderLineDelete", "Order"))
.Events(events => events.Error("error_handler"))
))
JavaScript is as follows:
function OpenItemhistoryPopup(stockCode) {
try {
if (stockCode == null) {
return;
}
var url = '@ConfigurationManager.AppSettings["BaseUrl"]Order/ItemPriceHistory?stockCode=' + stockCode;
$("#windowfritempricehistory").data("kendoWindow").open();
$("#windowfritempricehistory").data("kendoWindow").refresh(url);
$("#windowfritempricehistory").data("kendoWindow").center();
} catch (e) {
alert(e);
}
}
C# code
public ActionResult Itempricehistorydetails([DataSourceRequest] DataSourceRequest request, string searchvalue)
{
return Json(Itempricehistorydetails(searchvalue).ToDataSourceResult(request), JsonRequestBehavior.AllowGet);
}
private IQueryable<Itempricehistory> Itempricehistorydetails(string stockcode)
{
string city = (string)(Session["password"]);
int intstockcode = Convert.ToInt32(stockcode);
SessionContext sessionContext = CurrentSession;
string myObUrl = sessionContext.Url;
string myObUser = sessionContext.LogInUserName;
string myObPassword = city;
string custcode = sessionContext.CurrentCustomerId;
string dtfrom = DateTime.Now.AddYears(-1).ToString("dd/MM/yyyy");
string dateTo = DateTime.Now.ToString("dd/MM/yyyy");
string url = ConfigurationManager.AppSettings["BaseServiceUrl"] + "Order/GetSalesHistoryByCustomerByInventoryId? &user=" + myObUser + "&password=" + myObPassword + "&customerId=" + custcode + "&itemCode=" + intstockcode + "&dateFrom=" + dtfrom + "&dateTo=" + dateTo;
string jSon = CallApi(url);
List<Itempricehistory> orders = new JavaScriptSerializer().Deserialize<List<Itempricehistory>>(jSon);
DataSet dt = new DataSet();
List<Itempricehistory> converttolist = new List<Itempricehistory>();
Type elementType = typeof(Itempricehistory);
DataSet ds = new DataSet();
DataTable t = new DataTable();
ds.Tables.Add(t);
foreach (var propInfo in elementType.GetProperties())
{
Type ColType = Nullable.GetUnderlyingType(propInfo.PropertyType) ?? propInfo.PropertyType;
t.Columns.Add(propInfo.Name, ColType);
}
foreach (Itempricehistory item in orders)
{
DataRow row = t.NewRow();
foreach (var propInfo in elementType.GetProperties())
{
row[propInfo.Name] = propInfo.GetValue(item, null) ?? DBNull.Value;
}
t.Rows.Add(row);
}
List<Itempricehistory> convertreturntolist = new List<Itempricehistory>();
t.Columns.Add("DateStr");
t.AcceptChanges();
foreach (DataRow dr in t.Rows)
{
DateTime dDate;
try
{
dDate = Convert.ToDateTime(dr["Date"]);
dr["DateStr"] = dDate.ToString("yyyy-MM");
}
catch (Exception)
{
throw;
}
}
t.AcceptChanges();
t = t.AsEnumerable().GroupBy(r => r.Field<string>("DateStr")).Select(g => g.FirstOrDefault()).CopyToDataTable();
DataTable dtnew = new DataTable();
DataView view = t.DefaultView;
view.Sort = "DateStr DESC";
dtnew = view.ToTable();
List<Itempricehistory> data = new List<Itempricehistory>();
foreach (DataRow row in dtnew.Rows)
{
data.Add(new Itempricehistory
{
CustomerId = row["CustomerId"].ToString(),
CustomerName = row["CustomerName"].ToString(),
CustomerOrderNumber = row["CustomerOrderNumber"].ToString(),
CustomerTaxZone = row["CustomerTaxZone"].ToString(),
Date = row["DateStr"].ToString(),
DiscAmt = row["DiscAmt"].ToString(),
InventoryId = row["InventoryId"].ToString(),
ItemDescription = row["ItemDescription"].ToString(),
LineTotal = row["LineTotal"].ToString(),
OpenQty = row["OpenQty"].ToString(),
OrderNbr = row["OrderNbr"].ToString(),
OrderTotal = row["OrderTotal"].ToString(),
QtyOnShipments = row["QtyOnShipments"].ToString(),
Quantity = row["Quantity"].ToString(),
TaxCategory = row["TaxCategory"].ToString(),
TaxId = row["TaxId"].ToString(),
TaxRate = row["TaxRate"].ToString(),
UnitPrice = row["UnitPrice"].ToString(),
UOM = row["UOM"].ToString(),
StockCode = row["StockCode"].ToString()
});
}
return data.AsQueryable();
}