I have a kendo grid and I want to add a new line in there. There is a dropdown list in the grid to restrict users not to use anything other than what is in the DB. Whole thing works fine but when I try to add a new row or edit a row and doesn't select value from dropdown, kendo sends a null value.. it only sends value only if I change the dropdown but at least it should send the default value or the current value...
$("#HoleGrid").kendoGrid({
dataSource: {
transport: {
read: {
url: "SignOff/GetHoleData",
type: "POST",
datatype: "json",
contentType: "application/json"
},
update: {
url: "SignOff/UpdateHoleData",
contentType: "application/json; charset=utf-8",
type: "POST",
dataType: "json",
},
create: {
url: "SignOff/CreateHoleData",
contentType: "application/json; charset=utf-8",
type: "POST",
dataType: "json"
},
parameterMap: function (HoleData, operation) {
if (operation != "read") {
return kendo.stringify(HoleData.models);
}
}
},
serverPaging: false,
pageSize: 5,
batch: true,
schema: {
model: {
id: "ID",
fields: {
ID: { editable: false },
Hole: { editable: true, nullable: false },
From: { type: "number", validation: { required: true, min: 0 } },
To: { type: "number", validation: { required: true, min: 0 } },
Total: { editable: false },
Hours: { type: "number", validation: { min: 0, required: true } },
Bit: { defaultValue: { CategoryID: "BQ", CategoryName: "BQ" } },
Size: { editable: true, nullable: true },
TypeOfDrilling: { defaultValue: { CategoryID: "DIA", CategoryName: "DIA" } }
}
},
errors: "Errors"
},
error: function (e) {
alert(e.errors + "HoleGrid");
}
},
editable: "inline",
pageable: {
refresh: true,
pageSizes: true
},
toolbar: ["create"],
sortable: true,
autoBind: false,
columns:
[
{ field: "Hole", width: 90, title: "Hole" },
{ field: "From", width: 90, title: "From" },
{ field: "To", width: 90 },
{ field: "Total", width: 70, title: "Total" },
{ field: "Hours", width: 90, title: "Hours" },
{ field: "Bit", width: 80, title: "Bit#", values: BitSize },
{ field: "Size", width: 80, title: "Bit Size" },
{ field: "TypeOfDrilling", width: 80, title: "Type", values: Types },
{ width: 175, command: [{ name: "edit", text: { edit: "Edit", update: "Update", cancel: "Cancel" } }], title: "Action" },
]
});
});
var BitSize = [
{ value: 'BQ', text: 'BQ' },
{ value: 'NQ', text: 'NQ' },
{ value: 'HQ', text: 'HQ' },
{ value: 'PQ', text: 'PQ' },
{ value: 'RC', text: 'RC' },
{ value: 'GC', text: 'GC' }
];
var Types = [
{ value: 'DIA', text: 'DIA' },
{ value: 'RC', text: 'RC' },
{ value: 'GC', text: 'GC' }
];
Here is my Html
<div class="box-content">
<p>Holes</p>
<div id="HoleGrid"></div>
<div class="clearfix"></div>
</div>
Here are my demo MVC controller codes
[HttpPost]
public ContentResult UpdateHoleData(List<HoleViewModel> Holes)
{
return null;
}
[HttpPost]
public ContentResult CreateHoleData(List<HoleViewModel> Holes)
{
return null;
}
[HttpPost]
public ContentResult GetHoleData([DataSourceRequest]DataSourceRequest request)
{
string HolesJsonData = "{"ID":"0","Angle":"10","Area":"","Azimuth":"0","Bit":"","Condition":"","From":"0","GPS":"","Hammer":"63412-63412","Hole":"WP10B","HoleCondition":"","Hours":"11","ProgressiveTotal":"0","Purpose":"","RunSheetBitList":"","SiteID":"Geita-NY-CUT 7","Size":"RC","Status":"No","To":"102","Total":"102","TypeOfDrilling":"RC"},{"ID":"1","Angle":"0","Area":"","Azimuth":"0","Bit":"HQ","Condition":"","From":"0","GPS":"","Hammer":"","Hole":"WP12C","HoleCondition":"","Hours":"10","ProgressiveTotal":"0","Purpose":"","RunSheetBitList":"","SiteID":"Geita-NY-CUT 7","Size":"RC","Status":"No","To":"42","Total":"42","TypeOfDrilling":"RC"}";
return new ContentResult { Content = "[" + HolesJsonData + "]", ContentType = "application/json", ContentEncoding = Encoding.UTF8 };
}
And lastly
public class HoleViewModel
{
public string ID { get; set; }
public string Angle { get; set; }
public string Area { get; set; }
public string Azimuth { get; set; }
public string Bit { get; set; }
public string Condition { get; set; }
public string From { get; set; }
public string GPS { get; set; }
public string Hammer { get; set; }
public string Hole { get; set; }
public string HoleCondition { get; set; }
public string Hours { get; set; }
public string ProgressiveTotal { get; set; }
public string Purpose { get; set; }
public string RunSheetBitList { get; set; }
public int SiteID { get; set; }
public string Size { get; set; }
public string Status { get; set; }
public string To { get; set; }
public string Total { get; set; }
public string TypeOfDrilling { get; set; }
}
Where am I doing wrong?? Please help.
schema: {
model: {
id: "ID",
fields: {
ID: { editable: false },
Hole: { editable: true, nullable: false },
From: { type: "number", validation: { required: true, min: 0 } },
To: { type: "number", validation: { required: true, min: 0 } },
Total: { editable: false },
Hours: { type: "number", validation: { min: 0, required: true } },
Bit: { },
Size: { editable: true, nullable: true },
TypeOfDrilling: { } }
}
},
remove the default value of the dropdowns
I couldn't find any solution for that. So what I did, I check if it is null in the code behind and just put the default value in there manually..
public ContentResult UpdateHoleData(List<HoleViewModel> Holes)
{
if (Holes != null && Holes.Count > 0)
{
if (Holes[0].Size == null)
{
Holes[0].Size = "RC";
}
if (Holes[0].TypeOfDrilling == null)
{
Holes[0].TypeOfDrilling = "DIA";
}
}
return null;
}
Related
Filling the Total Column with the jqxgrid Multiplier.
Hi there;
I want to multiply ItemQty and SinglePrice columns and write to TotalPrice column.
How can I do that.
I tried to use the code in this link but it didn't work.
The other columns show the data in the database.
var initFBListGrid=function(){
source =
{
dataType: 'json',
datafields: [
{ name: 'Id' },
{ name: 'OrderNumber' },
{ name: 'LineNumber' },
{ name: 'ItemNumber' },
{ name: 'ItemDescription' },
{ name: 'ItemQty' },
{ name: 'SinglePrice' },
{ name: 'Ixitem' },
{ name: 'IsUrgentHTML' },
{ name: 'StatusHTML' },
{ name: 'IsApproved' },
{ name: 'IsRejected' },
{ name: 'LatestPurchasePrice' },
{ name: 'PriceLevel' },
{ name: 'DeliveryDate' },
{ name: 'SupplierID' },
{ name: 'SupplierName' },
{ name: 'ProjectNumber' },
{ name: 'ProjectName' },
{ name: 'BuyerName' },
{ name: 'PendingApproverName' },
{ name: 'Company' },
{ name: 'Currency' },
{ name: 'HasAttachmentHTML' },
{ name: 'Glco' },
{ name: 'RequesterName' },
{ name: 'ApproverName' },
{
name: 'TotalPrice',
formatter: function (cellvalue, options, rowObject) {
var ItemQty = parseInt(rowObject.ItemQty, 10),
SinglePrice = parseInt(rowObject.SinglePrice,10);
return $.fmatter.util.NumberFormat(ItemQty * SinglePrice, $.jgrid.formatter.currency);
}
}
],
id: 'Id'
};
i have a project in which i have to write nested attribute in rswag
{
"question_bank": {
"question_exams_attributes": {
"0": {
"question_bank_id": "",
"exam_id": "12",
"sub_category_id": "23",
"_destroy": "false"
}
},
"question_type": "Single best answer",
"difficulty": "easy",
"status": "active",
"tag_list": [
""
],
"question": "testing api 2"
},
"commit": "Submit"
}
i am trying to write this json body in nested attribute syntax in rswag:
i have tried this:
parameter name: :question_bank, in: :body, schema: {
type: :object,
properties: {
question_exams_attributes: {
type: :object,
properties: {
'0': {
properties: {
question_bank_id: { type: :string },
exam_id: { type: :string },
sub_category_id: { type: :string }
}
}
}
}
}
}
I faced a similar issue too.
Here is how I solved it.
schema type: :object,
properties: {
title: { type: :string },
content: { type: :string },
comments: {
type: :array,
items: {
type: :object,
properties: {
content: { type: :string }
}
}
}
}
In your case I think you're missing the type on the "0" element.
properties: {
question_exams_attributes: {
type: :object,
properties: {
'0': {
type: :object,
properties: {
question_bank_id: { type: :string },
exam_id: { type: :string },
sub_category_id: { type: :string }
}
}
}
}
}
I'm implementing an asp.net MVC application that includes a page with nested data Grid. Currently, I'm binding data using a single complex data object and it's loading data correctly.
But the problem is when inner grids have so much data it takes some time to get data from the database and make a data object for all the rows.
What I need to do is get and bind inner grid data when the user expands the selected row.
<div class="panel panel-default">
<div class="panel-body">
<div id="purchase-order-grid"></div>
</div>
</div>
$(document).ready(function () {
$("#purchase-order-grid").kendoGrid({
columns: [
{
field: "PurchaseOrderNumber",
title: "Purchase Order",
width: 80,
headerAttributes: { style: "text-align:center" },
attributes: { style: "text-align:center" }
},
{
field: "Store",
title: "Store",
width: 100,
headerAttributes: { style: "text-align:center" },
attributes: { style: "text-align:center" }
}
],
detailTemplate: '<div class="second-level-grid"></div>',
detailInit: function (e) {
e.detailRow.find(".second-level-grid").kendoGrid({
dataSource: e.data.Products,
columns: [
{
field: "PartNumber",
title: "Part",
width: 70
},
{
field: "Description",
title: "Description",
width: 150
}
]
})
},
dataSource: {
type: "json",
transport: {
read: {
url: "#Html.Raw(Url.Action("List", "PurchasingPurchaseOrder"))",
type: "POST",
dataType: "json",
data: additionalData
}
}
}
});
}
function additionalData() {
var data = {
StoreId: $('##Html.IdFor(model => model.StoreId)').val()
};
addAntiForgeryToken(data);
return data;
}
[HttpPost]
public virtual IActionResult List(PurchaseOrderSearchModel model, DataSourceRequest command)
{
int totalCount = 0;
var purchaseOrder = _purchaseOrderService.GetPurchaseOrdersWithSearchOption(model, out totalCount, command.Page - 1, command.PageSize);
return Json(new DataSourceResult { Data = purchaseOrder, Total = totalCount });
}
I found a solution finally. Adding full code for future references.
<div class="panel panel-default">
<div class="panel-body">
<div id="purchase-order-grid"></div>
</div>
</div>
var expanded = {};
var grid, id;
$(document).ready(function () {
var element = $("#purchase-order-grid").kendoGrid({
dataSource: {
type: "json",
transport: {
read: {
url: "#Html.Raw(Url.Action("List", "PurchasingPurchaseOrder"))",
type: "POST",
dataType: "json",
data: additionalData
}
},
schema: {
data: "Data",
total: "Total",
errors: "Errors"
},
error: function (e) {
display_kendoui_grid_error(e);
// Cancel the changes
this.cancelChanges();
},
pageSize: #(defaultGridPageSize),
serverPaging: true,
serverFiltering: true,
serverSorting: true
},
sortable: true,
pageable: true,
detailInit: detailInit,
dataBound: function (e) {
grid = this;
grid.tbody.find("tr[role='row']").each(function () {
var id = grid.dataItem(this).PurchaseOrderNumber;
if (expanded.hasOwnProperty(id) && expanded[id]) {
grid.expandRow(this);
}
});
},
detailExpand: function (e) {
id = this.dataItem(e.masterRow).PurchaseOrderNumber;
expanded[id] = true;
},
detailCollapse: function (e) {
id = this.dataItem(e.masterRow).PurchaseOrderNumber;
expanded[id] = false;
},
columns: [
{
field: "Store",
title: "Store",
width: 100,
headerAttributes: { style: "text-align:center" },
attributes: { style: "text-align:center" }
},
{
field: "POCreatedOn",
title: "PO Created On",
width: 100,
headerAttributes: { style: "text-align:center" },
attributes: { style: "text-align:center" }
},
{
field: "SalesOrderTotal",
title: "Sales Order Total",
width: 80,
headerAttributes: { style: "text-align:right" },
attributes: { style: "text-align:right" }
},
{
field: "TotalPOCost",
title: "Total PO Cost (€)",
width: 100,
headerAttributes: { style: "text-align:right" },
attributes: { style: "text-align:right" }
},
{
field: "ShipmentStatus",
title: "Shipment Status",
width: 100,
headerAttributes: { style: "text-align:center" },
attributes: { style: "text-align:center" }
},
{
field: "PaymentStatus",
title: "Payment Status",
width: 90,
headerAttributes: { style: "text-align:center" },
attributes: { style: "text-align:center" }
}
]
});
});
function detailInit(e) {
$("<div/>").appendTo(e.detailCell).kendoGrid({
dataSource: {
type: "json",
transport: {
read: {
url: "#Html.Raw(Url.Action("GetPurchaseOrderByPurchaseOrderNumber", "PurchasingPurchaseOrder"))",
type: "POST",
dataType: "json",
data: nestedGridData(e.data.PurchaseOrderNumber)
}
},
schema: {
data: "Data",
total: "Total",
errors: "Errors"
},
serverPaging: true,
serverSorting: true,
serverFiltering: true,
pageSize: 5,
filter: { field: "PurchaseOrderNumber", operator: "eq", value: e.data.PurchaseOrderNumber }
},
scrollable: false,
sortable: true,
pageable: true,
columns: [
{
field: "Description",
title: "Description",
width: 150
},
{
field: "SalesOrderId",
title: "Order",
width: 80,
template:'#=formatSalesOrderIds(SalesOrderId)#',
headerAttributes: { style: "text-align:center" },
attributes: { style: "text-align:center" }
},
{
field: "QuantityOrdered",
title: "Qty Order",
width: 70,
headerAttributes: { style: "text-align:center" },
attributes: { style: "text-align:center" }
},
{
field: "QuantityDispatched",
title: "Qty Shipped",
width: 70,
headerAttributes: { style: "text-align:center" },
attributes: { style: "text-align:center" }
}
]
});
}
function nestedGridData(purchaseOrderNumber) {
var data = {
GoDirectlyToPurchaseOrderId: purchaseOrderNumber
};
addAntiForgeryToken(data);
return data;
}
public class PurchasingPurchaseOrderController
{
[HttpPost]
public virtual IActionResult List(PurchaseOrderSearchModel model, DataSourceRequest command)
{
int totalCount = 0;
var purchaseOrder = GetPurchaseOrdersWithSearchOption(model, out totalCount, command.Page - 1, command.PageSize);
return Json(new DataSourceResult { Data = purchaseOrder, Total = totalCount
});
}
[HttpPost]
public virtual IActionResult GetPurchaseOrderByPurchaseOrderNumber(PurchaseOrderSearchModel model, DataSourceRequest command)
{
int totalCount = 0;
var products= GetPurchaseOrderByPurchaseOrderNumber(model, out totalCount, command.Page - 1, command.PageSize);
return Json(new DataSourceResult { Data = products, Total = totalCount });
}
}
public class DataSourceRequest
{
public DataSourceRequest()
{
this.Page = 1;
this.PageSize = 10;
}
public int Page { get; set; }
public int PageSize { get; set; }
public List<Sort> Sort { get; set; }
}
I'm using jsTree plugin in my ASP.NET MVC application and have a strange issue. I've attached contextMenu plugin, but its items have a strange empty space on the left, like in the image below:
My code is followed:
$(function () {
$("#competence-areas-tree").jstree({
core: {
data: {
cache: false,
url: '#Url.Action("GetTreeData", "CompetenceArea")'
},
multiple: false
},
types: {
competenceArea: {
icon: "#Url.Stylesheet("/jstree-3.0.0b/competenceArea.png")"
}
},
contextmenu: {
items: function ($node) {
return {
createItem: {
separator_before: false,
separator_after: false,
label: "Создать",
submenu: {
create: {
separator_before: false,
separator_after: false,
label: "Создать на текущем уровне",
action: function() {
Create($node.parent);
}
},
createChild: {
separator_before: false,
separator_after: false,
label: "Создать потомка",
action: function() {
Create($node.id);
}
}
}
},
editItem: {
separator_before: false,
separator_after: false,
label: "Редактировать",
action: function() {
Edit($node.id);
}
},
deleteItem: {
separator_before: false,
separator_after: false,
label: "Удалить",
action: function() {
Delete($node.id);
}
},
detailGraphItem: {
separator_before: false,
separator_after: false,
label: "Перейти к графу",
action: function() {
DetailGraph($node.id);
}
}
}
}
},
plugins: ["types", "contextmenu", "themes"]
}).on("changed.jstree", function(e, data) {
if (data.action === "select_node") {
OnSelectingNode(data.node.original.id);
}
});
});
Thank you!
Hmm I made a jsfiddle for the context menu you have provided but there isn't anything wrong with it. There is always a default space to the left with the context menu in the jstree but not to the extent that you're having. Here is the jsfiddle to see if that can help:
http://jsfiddle.net/3q9Ma/529/
$(function () {
var data = [
{ "id" : "ajson1", "parent" : "#", "text" : "Simple root node" },
{ "id" : "ajson2", "parent" : "#", "text" : "Root node 2" },
{ "id" : "ajson3", "parent" : "ajson2", "text" : "Child 1" },
{ "id" : "ajson4", "parent" : "ajson2", "text" : "Child 2" },
];
$("#jstree").jstree({
"core" : {
"check_callback" : true,
"data": data
},
"plugins" : [ "contextmenu", "dnd"],
contextmenu: {
items: function ($node) {
return {
createItem: {
separator_before: false,
separator_after: false,
label: "Создать",
submenu: {
create: {
separator_before: false,
separator_after: false,
label: "Создать на текущем уровне",
action: function() {
Create($node.parent);
}
},
createChild: {
separator_before: false,
separator_after: false,
label: "Создать потомка",
action: function() {
Create($node.id);
}
}
}
},
editItem: {
separator_before: false,
separator_after: false,
label: "Редактировать",
action: function() {
Edit($node.id);
}
},
deleteItem: {
separator_before: false,
separator_after: false,
label: "Удалить",
action: function() {
Delete($node.id);
}
},
detailGraphItem: {
separator_before: false,
separator_after: false,
label: "Перейти к графу",
action: function() {
DetailGraph($node.id);
}
}
}
}
}
}).on('create_node.jstree', function(e, data) {
console.log('saved');
});
$("#sam").on("click",function() {
$('#jstree').jstree().create_node('#' , { "id" : "ajson5", "text" : "newly added" }, "last", function(){
alert("done");
});
});
});
I want to set filetype according to click on export menu on the right in the given url. For example if click on pdf then filetype should be set as application/pdf.
var defaultTitle = "Kalar";
var drilldownTitle = "";
var ydrillupTitle = "# of Kalar";
var ydrilldownTitle = "";
var chart = new Highcharts.Chart({
chart: {
type: 'column',
renderTo: 'upendra',
events: {
drilldown: function(e) {
chart.setTitle({ text: drilldownTitle + e.point.title });
chart.yAxis[0].axisTitle.attr({
text: ydrilldownTitle
});
},
drillup: function(e) {
chart.setTitle({ text: defaultTitle });
chart.yAxis[0].axisTitle.attr({
text: ydrillupTitle
});
},
click: function(e) {
chart.exportChart({
filename: chart.options.title.text
});
}
}
},
title: {
text: defaultTitle
},
subtitle: {
text: ''
},
credits: {
enabled: false
},
xAxis: {
categories: ['one', 'two']
},
yAxis: {
allowDecimals: false,
min: 0,
title: {
text: ydrillupTitle
}
},
plotOptions: {
column: {
stacking: 'normal',
showInLegend: true
}
},
series:[
{
name:'A',
color:'#E9ECEE',
tooltip: {
headerFormat: '',
pointFormat: '{point.name}:<br/><b>{point.y}</b> Bookings (<b>{point.percentage:, .1f} %</b>)<br/>'
},
data:[
{
name: "A",
title: "A by Company",
x:0, y:2
}, {
name: "",
x:1, y:0
}
]
},
{
name:'Arrived',
color:'#B3E5C4',
tooltip: {
headerFormat: '',
pointFormat: '{point.name}:<br/><b>{point.y}</b> Bookings (<b>{point.percentage:, .1f} %</b>)<br/>'
},
data:[
{
name: "Arrived",
title: "Planned Bookings by Goods Type",
x:0, y:10
}, {
name: "",
x:1, y:0
}
]
},
{
name:'Unscheduled',
color:'#A9ABAD',
tooltip: {
headerFormat: '',
pointFormat: '{point.name}:<br/><b>{point.y}</b> Deliveries (<b>{point.percentage:, .1f} %</b>)<br/>'
},
data:[
{
name: "",
x:0, y:0
},
{
name: "Unscheduled",
title: "Unscheduled Deliveries by Company",
x:1, y:8
}
]
},
{
name:'Rejected',
color:'#FF838F',
tooltip: {
headerFormat: '',
pointFormat: '{point.name}:<br/><b>{point.y}</b> Deliveries (<b>{point.percentage:, .1f} %</b>)<br/>'
},
data:[
{
name: "",
x:0, y:0
},
{
name: "Rejected",
title: "Rejected Deliveries Reasons",
x:1, y:7
}
]
},
{
name:'Complete',
color:'#B3E5C4',
tooltip: {
headerFormat: '',
pointFormat: '{point.name}:<br/><b>{point.y}</b> Deliveries (<b>{point.percentage:, .1f} %</b>)<br/>'
},
data:[
{
name: "",
x:0, y:0
},
{
name: "Complete",
title: "Actual Deliveries by Goods Type",
x:1, y:6
}
]
}
]
});
});
You can edit menuItems in exporting options and then set filename, extracting that information from title.
exporting: {
buttons: {
contextButton: {
menuItems: [{
textKey: 'printChart',
onclick: function () {
this.print();
}
}, {
separator: true
}, {
textKey: 'downloadPNG',
onclick: function () {
var title = this.title.textStr;
this.exportChart({
type: 'image/png',
filename: title
});
}
}, {
textKey: 'downloadJPEG',
onclick: function () {
var title = this.title.textStr;
this.exportChart({
type: 'image/jpeg',
filename: title
});
}
}, {
textKey: 'downloadPDF',
onclick: function () {
var title = this.title.textStr;
this.exportChart({
type: 'application/pdf',
filename: title
});
}
}, {
textKey: 'downloadSVG',
onclick: function () {
var title = this.title.textStr;
this.exportChart({
type: 'image/svg+xml',
filename: title
});
}
}]
}
}
},
Example: http://jsfiddle.net/bmp6Leh5/4/