I'm working on kendoui. If we observe a grid then all the values are on the left side of each cell.I have a field of price and i want its value on the right side of cell.
Is it possible in kendo ui?
My code :-
<div id="grid"></div>
<script>
$(document).ready(function () {
var crudServiceBaseUrl = ${grailsApplication.config.grails.serverURL}"+/course/,
dataSource = new kendo.data.DataSource({
transport: {
read: {
url: crudServiceBaseUrl+"listAll", dataType: "json",
cache: false
},
parameterMap: function(options, operation) {
if (operation !== "read" && options.models) {
return {models:
kendo.stringify(options.models)};
}
}
},
batch: true,
pageSize: 15,
sort: { field: "dateCreated", dir: "desc" },
schema: {
model: {
id: "id",
fields: {
name: { editable: false, type: "string", validation: { required:
true, min: 1} },
type: { editable: false, type: "Type",validation: { required: true, min: 1}
},
fee: { editable: false, type: "double",validation: { required: true, min: 1}
},
duration: { editable: false, type: "integer", validation: { required: true, min: 1} },
status: { editable: false, type:"Status" , validation: { required: true, min: 1} }
}
}
}
});
$("#grid").kendoGrid({
dataSource: dataSource,
navigatable: true,
pageable: true,
groupable:true,
sortable:true,
selectable:true,
height: 300,
columns: [
{field: "name",
title:'<g:message code="grid.billingServicesGroup.holidayName.label"
default="Course Name" />'},
{field: "type.name",
title:'<g:message code="grid.billingServicesGroup.reason.label"
default="Type of course" />'},
{field: "fee",title:'<g:message
code="grid.billingServicesGroup.code.label"
default="Fee" />'},
{field: "duration",title:'
<g:message code="grid.billingServicesGroup.holidayDate.label"
default="Duration(Year)" />'}
,
{field: "status.name",title:'<g:message
code="grid.billingServicesGroup.status.label" default="Status" />'},
],
editable: true,
change:function(e){
idOfData=this.select().data("id");
window.location.href=crudServiceBaseUrl+"show/"+idOfData;
},
saveChanges:function(){
},
remove:function(e){
/*alert(e.model.id.value);
selectedId=this.select().data("id");
$.ajax({
url:"http://localhost:8080/billing-
app/api/skeletonBill/"+selectedId,
type:"DELETE"
}).done(function(){alert('deleted')});*/
},
scrollable: {
virtual: true
}
});
});
</script>
You can use a column template to wrap the contents of all the cells in that column in for example a div-tag.
You can then use a class on the div to style the contents using CSS.
For example:
columns:
[{
field:"Department",
title:"Department",
width:80,
template: "<div class='foobar'>#= Department#</div>"
}]
/* CSS */
.foobar {
width: 100%;
text-align: right;
}
Related
`
class TransactionsGrid {
constructor(productInfoWindowId) {
this._productInfoWindowId = productInfoWindowId;
this._gridTransactionsSelectorId = this._productInfoWindowId + " " + "#gridTransactions";
}
async setGrid(inventoryId, productId) {
this._inventoryId = inventoryId;
this._productId = productId;
let userStore = new UserStore();
$(this._gridTransactionsSelectorId).kendoGrid({
allowCopy: true,
resizable: true,
reorderable: true,
columnMenu: true,
scrollable: true,
selectable: "row",
persistSelection: true,
navigatable: true,
sortable: true,
filterable: {
mode: "menu"
},
pageable: {
pageSizes: [100, 200, 300, "all"],
numeric: false
},
height: window.innerHeight - 200,
columns: [
{
field: "OrderType",
title: userStore.translatedString("frmPurchaseOrder.OrderType"),
width: 120
},
{
field: "DocumentNo",
title: userStore.translatedString("frmCreatePurchaseOrders.DocumentNo"),
width: 130,
},
{
field: "ActorNo",
title: userStore.translatedString("Common.ActorNo"),
width: 120
},
{
field: "Actor",
title: userStore.translatedString("Common.Actor"),
width: 120,
},
{
field: "TransactionDate",
title: userStore.translatedString("uctrlInventoryTrans.TransactionDate"),
width: 125,
attributes: {
style: 'text-align: right;'
},
format: "{0:yyyy-MM-dd}"
},
{
field: "Quantity",
title: userStore.translatedString("Common.Quantity"),
width: 120,
attributes: {
style: 'text-align: right;'
},
format: "{0:n2}"
},
{
field: "QtyAfterTransactions",
title: userStore.translatedString("Common.QtyAfterTransactions"),
width: 120,
attributes: {
style: 'text-align: right;'
},
format: "{0:n2}"
}
],
dataBound: async function (e) {
var rows = e.sender.content.find('tr');
rows.each(function (index, row) {
var dataItem = e.sender.dataItem(row);
if (dataItem.QtyAfterTransactions < 0) {
$(row).children().addClass('lightRed');
}
});
},
dataSource: {
dataType: "json",
schema: {
model: {
fields: {
InventoryId: { type: "number", editable: false },
ProductID: { type: "number", editable: false },
OrderType: { type: "string", editable: false },
DocumentNo: { type: "number", editable: false },
ActorNo: { type: "number", editable: false },
Actor: { type: "string", editable: false },
TransactionDate: { type: "date", editable: false},
Quantity: { type: "decimal", editable: false },
QtyAfterTransactions: { type: "decimal", editable: false }
}
}
},
batch: false,
transport: {
read: function (options) {
$.ajax({
url: "/ProductRowInfoSite/GetTransactions",
data: {
"inventoryId": inventoryId,
"productId": productId
},
dataType: "json", // "jsonp" is required for cross-domain requests; use "json" for same-domain requests
success: function (result) {
// notify the data source that the request succeeded
options.success(result);
misc.SelectFirstRowInGrid(self._gridTransactionsSelectorId);
},
error: function (jqXHR, textStatus, errorThrown) {
displayAjaxError(jqXHR, textStatus, errorThrown);
// notify the data source that the request failed
options.error(jqXHR);
},
type: 'POST'
});
}
},
pageSize: 100
}
});
}
}
` $(this._gridTransactionsSelectorId).kendoGrid({
allowCopy: true,
resizable: true,
reorderable: true,
columnMenu: true,
scrollable: true,
selectable: "row",
persistSelection: true,
navigatable: true,
sortable: true,
filterable: {
mode: "menu"
},
pageable: {
pageSizes: [100, 200, 300, "all"],
numeric: false
},
height: window.innerHeight - 200,
columns: [
{
field: "OrderType",
title: userStore.translatedString("frmPurchaseOrder.OrderType"),
width: 120
},
{
field: "DocumentNo",
title: userStore.translatedString("frmCreatePurchaseOrders.DocumentNo"),
width: 130,
},
{
field: "ActorNo",
title: userStore.translatedString("Common.ActorNo"),
width: 120
},
{
field: "Actor",
title: userStore.translatedString("Common.Actor"),
width: 120,
},
{
field: "TransactionDate",
title: userStore.translatedString("uctrlInventoryTrans.TransactionDate"),
width: 125,
attributes: {
style: 'text-align: right;'
},
format: "{0:yyyy-MM-dd}"
},
{
field: "Quantity",
title: userStore.translatedString("Common.Quantity"),
width: 120,
attributes: {
style: 'text-align: right;'
},
format: "{0:n2}"
},
{
field: "QtyAfterTransactions",
title: userStore.translatedString("Common.QtyAfterTransactions"),
width: 120,
attributes: {
style: 'text-align: right;'
},
format: "{0:n2}"
}
],
I'm using a Kendo Grid, with Server Side Filtering, Sorting and Pagination.
This my code for initializing the Grid:
In this code Server side pagination and virtual scroll is working but filtering and shorting is not working.
In any request, I am getting this
type of request parameters.
[HttpPost]
public JsonResult getGridData([DataSourceRequest] DataSourceRequest request)
{
var userList = data;
return Json(userList.ToDataSourceResult(request));
}
$("#grid").kendoGrid({
dataSource: {
type: "aspnetmvc-ajax",
transport: {
read: {
url: "#Url.Action("getGridData", "ListMaster")",
type: "POST",
dataType: "json",
async: true,
contentType: 'application/json',
data: function (e) {
return e;
}
}
,parameterMap: function (data, type) {
return kendo.stringify(data);
}
},
schema: {
data: function (result) {
return result.Data;
},
total: function (result) {
return result.Total;
}
},
pageSize: 20,
serverPaging: true,
serverFiltering: true,
serverSorting: false
},
height: 550,
groupable: true,
sortable: true,
pageable: true,
resizable: true,
scrollable: { virtual: true },
filterable: { mode: 'row' },
pageable: {
refresh: true,
pageSizes: true,
buttonCount: 5
},
dataBound: function () {
var data = this.dataSource.view();
},
columns: [{ field: "Id", title: "Id", filterable: filter(true), hidden: true },
{ field: "Name", title: "Name", filterable: filter(true) }]
});
$("#grid").kendoGrid({
dataSource: {
type: "json",
transport: {
read: {
url: "#Url.Action("getGridData", "ListMaster")",
type: "POST",
dataType: "json",
async: true,
cache: false,
contentType: 'application/json',
data: function (e) {
return e;
}
},
parameterMap: function (data, type) {
return kendo.stringify(data);
}
},
schema: {
data: function (result) {
return result.Data;
},
total: function (result) {
return result.Total;
}
},
pageSize: 20,
serverPaging: true,
serverFiltering: true,
serverSorting: false
},
height: 550,
groupable: true,
sortable: true,
pageable: true,
resizable: true,
scrollable: { virtual: true },
filterable: {
mode: 'row',
operators: {
string: {
contains: "contains"
}
} },
pageable: {
refresh: true,
pageSizes: true,
buttonCount: 5
},
dataBound: function () {
var data = this.dataSource.view();
},
columns: [{ field: "Id", title: "Id", filterable: filter(true), hidden: true },
{ field: "Name", title: "Name", filterable: filter(true) }]
});
My export excel toolbar works great when i don't use allPages = true.
with all pages option it doesn't raise any error and do nothing, I figured out this is may caused by lazy loading rows for each page.
I've searched a lot and found nothing for this problem.
<script>
$(document).ready(function () {
dataSource = new kendo.data.DataSource({
serverPaging: true,
serverSorting: true,
serverFiltering: true,
requestEnd: function (e) {
showServerMessageInGrid(e);
if (e.response.IsSuccess == false)
this.read();
},
transport: {
read: {
url: "#Url.Action("AjaxOrderList", "Order")",
dataType: "json",
type: "POST"
},
parameterMap: function (options, operation) {
if (operation == "read") {
return { options: kendo.stringify(options) };
}
if (operation !== "read") {
return {
models: kendo.stringify(options.models),
options: kendo.stringify(options)
};
}
}
},
batch: true,
pageSize: 20,
schema: {
data: 'ViewModel',
total: 'TotalCount',
model: {
id: "Id",
fields: {
Id: { width: 90, editable: false },
CityName: { width: 120, editable: false }
}
}
}
});
$("#grid").kendoGrid({
dataSource: dataSource,
toolbar:[{ name: "excel" }],
excel: {
fileName: "OrderList.xlsx",
filterable: true,
allPages: true
},
scrollable:true,
pageable: true,
selectable: true,
resizable: true,
filterable: true,
sortable: true,
columns: [
{ field: "Id", width: "90px", editable: false, filterable: filterableNumeric() },
{ field: "CityName", width: "120px", editable: false }
],
editable: "inline",
}
});
});
</script>
Any idea how can i export all pages with lazy loading?
I found my problem.
It was MaxJsonLength because the result of my action was new JavaScriptSerializer().Serialize(_orderList).
I solved it by Int32.MaxValue()
var json = new JavaScriptSerializer();
json.MaxJsonLength = Int32.MaxValue;
var jsonResult = json.Serialize(_orderList);
return jsonResult;
I am having problem getting the Kendo Grid to work correctly. I am using ASP.NET WebAPI to fetch data from SQL Server and display it in the grid. Use the Kendo Grid to do Updates and Deletes.
POST: While debugging I noticed that a NULL object in IE but Chrome gets a valid data.
which I am passing to update the DB.
IE versions 10 and 11. There are no JS errors but the object is NULL on the WEB API.
WEBAPI - GET Works (IE and Chrome),
POST/DELETE does not work in IE (Works in Chrome)
#model dynamic
#{
ViewBag.Title = "FunctionalGroup";
}
<div class=".col-xs-12 .col-sm-6 .col-lg-8">
<div class="well well-sm">
<h2>Functional Groups - Management</h2>
<p>Create, Update and Delete Functional Groups</p>
</div>
<div class="row">
<div class="well well-sm">
<div style="overflow-x: auto" id="FunctionalGroupGrid"></div>
<div id="window"></div>
</div>
</div>
<div>
<button data-role="button" data-icon="cancel"></button>
</div>
</div>
#section Scripts{
<script type="text/x-kendo-template" id="windowTemplate">
<p>Delete <strong>#= FunctionalGroupName #</strong> ? </p>
<p>#= FunctionalGroupDescription # </p>
<button class="k-button" id="yesButton">Yes</button>
<button class="k-button" id="noButton"> No</button>
</script>
<script>
var windowTemplate = kendo.template($("#windowTemplate").html());
var window = $("#window").kendoWindow({
title: "Are you sure you want to delete this record?",
visible: false, //the window will not appear before its .open method is called
modal: true,
resizable: false,
width: "400px",
height: "200px",
}).data("kendoWindow");
var LookupFunctionalGroupType = new kendo.data.DataSource({
transport: {
read: "/api/FunctionalGroupType",
datatype : "json"
}
});
function getfunctionalGroupType(functionalGroupTypeID) {
for (var idx = 0, length = LookupFunctionalGroupType.length; idx < length; idx++) {
if (LookupFunctionalGroupType[idx].FunctionalGroupTypeID === functionalGroupTypeID) {
return LookupFunctionalGroupType[idx].FunctionalGroupTypeName;
}
}
}
function functionalGroupTypeDropDownEditor(container, options) {
$('<input data-bind="value:' + options.field + '"/>')
.appendTo(container)
.kendoDropDownList({
dataTextField: "FunctionalGroupTypeName",
dataValueField: "FunctionalGroupTypeID",
dataSource: LookupFunctionalGroupType
}).appendTo(container);
}
$(function () {
var baseUrl = "/api/FunctionalGroup";
var datatype = "json";
var contentType = "application/json";
var datasourceFG = new kendo.data.DataSource({
serverPaging: true,
pageSize: 10,
autoSync: false,
batch: true,
transport: {
read: {
url: baseUrl,
dataType: datatype,
contentType: contentType
},
create: {
url: baseUrl,
dataType: datatype,
contentType: contentType,
type: "POST"
},
update: {
url: baseUrl,
dataType: datatype,
contentType: contentType,
type: "PUT"
},
destroy: {
url: baseUrl,
dataType: datatype,
contentType: contentType,
type: "DELETE"
}
, parameterMap: function (data, operation) {
if (operation !== "read" && data.models) {
return kendo.stringify(data.models);
}
else {
return {
take: data.take,
skip: data.skip,
pageSize: data.pageSize,
page:data.page
}
}
},
},
schema: {
data: "Data.$values",
total: "RecordCount",
model: {
id: "FunctionalGroupID",
fields: {
FunctionalGroupID: { editable: false, type: "number" },
FunctionalGroupName: { editable: true, nullable: false, validation: { required: true } },
FunctionalGroupDescription: { editable: true, nullable: false, validation: { required: true } },
FunctionalGroupTypeID: { field: "FunctionalGroupTypeID", type: "number", defaultValue: 101 },
IsActive: { editable: true, nullable: false, type: "boolean" },
CreatedBy: { editable: false, nullable: false, validation: { required: true } },
CreatedDateTime: { editable: false, type: "date", format: "{0:MM/dd/yyyy HH:mm:ss}" },
ModifiedBy: { editable: false},
ModifiedDateTime: { editable: false, type: "date", format: "{0:MM/dd/yyyy HH:mm:ss}" }
}
},
}
});
$("#FunctionalGroupGrid").kendoGrid({
dataSource: datasourceFG,
navigatable: true,
autoBind: false,
pageable: true,
resizable: true,
reorderable: true,
editable: kendo.support.mobileOS ? "popup":true,
groupable: true,
filterable: true,
sortable:true,
columnMenu: true,
selectable: "row",
mobile: true,
toolbar: ["create", "save", "cancel"],
columns: [
{ field: "FunctionalGroupID", width: 50, title: "ID", hidden: true },
{ field: "FunctionalGroupName", width: 150, title: "Functional Group" },
{ field: "FunctionalGroupDescription", width: 200, title: "Description" },
{
field: "FunctionalGroupTypeID", width: 180, title: "Functional Group Type"
, template: '#=getfunctionalGroupType(FunctionalGroupTypeID)#'
, editor: functionalGroupTypeDropDownEditor, filterable:false
},
{
field: "IsActive", width: 80, title: "Is Active",
template: '<input type="checkbox" #= IsActive ? checked="checked" : "" # disabled="disabled" ></input>'
},
{ field: "CreatedBy", width: 100, title: "Created By", hidden: true },
{ field: "CreatedDateTime", width: 100, title: "Created DateTime", format: "{0:MM/dd/yyyy}", hidden: true },
{ field: "ModifiedBy", width: 100, title: "ModifiedBy", hidden: true },
{ field: "ModifiedDateTime", width: 100, title: "Modified DateTime", format: "{0:MM/dd/yyyy}", hidden: true },
{
title: "Actions",
command: [
{
name: "destroy",
text: "Delete",
click: function (e) { //add a click event listener on the delete button
var tr = $(e.target).closest("tr"); //get the row for deletion
var data = this.dataItem(tr); //get the row data so it can be referred later
window.content(windowTemplate(data)); //send the row data object to the template and render it
window.open().center();
$("#yesButton").click(function () {
grid.dataSource.remove(data) //prepare a "destroy" request
//grid.dataSource.sync() //actually send the request (might be ommited if the autoSync option is enabled in the dataSource)
window.close();
})
$("#noButton").click(function () {
window.close();
})
}
}
]
}
]
});
LookupFunctionalGroupType.fetch(function () {
LookupFunctionalGroupType = this.data(); //First fetch the Lookup data
datasourceFG.read(); // This will bind to the grid.
});
});
</script>
Which versoin of IE are you running? Are you seeing JS error in IE?
I see in your secript
},
}
You might want to remove "," if there are no elements following it in the list
Using kendo grid with Popup edit. I verified the data is posted from the view (I can see it in the Network Tab, here is a look at it:
{"LetterId":12,"BodyText":"This is a test","CreatedDate":"07/31/2013","CreatedBy":"Grace Rodgers","ModifiedDate":"07/31/2013","ModifiedBy":"Grace Rodgers","PersonId":18,"FirstName":"Jason","LastName":"Bigby"}:
However, I have a breakpoint at the json method in the controller, and when hovering over the model parameter, in shows all fields are null. Here is the first couple lines of the controller code:
[HttpPost]
public JsonResult JsonEditLetter(LetterViewModel model)
{
and the kendo code in the view:
var PersId = $("#PersonId").val();
var ds_LettersGrid = new kendo.data.DataSource({
transport: {
read: {
url: '#Url.Action("JsonGetLetterList", "Letter")/' + PersId,
dataType: 'json'
},
update: {
url: '#Url.Action("JsonEditLetter", "Letter")',
dataType: 'json',
type: "POST"
},
parameterMap: function (data, type) {
if (type == "update") {
data.models[0].CreatedDate = kendo.toString(new Date(data.models[0].CreatedDate), "MM/dd/yyyy");
data.models[0].ModifiedDate = kendo.toString(new Date(data.models[0].ModifiedDate), "MM/dd/yyyy");
return kendo.stringify(data.models[0]);
}
},
},
batch: true,
schema: {
model: {
id: "LetterId",
fields: {
BodyText: { editable: true },
CreatedDate: { editable: false, type: "date"},
ModifiedDate: { editable: false, type: "date" },
CreatedBy: { editable: false},
ModifiedBy: { editable: false },
PersonId: { defaultValue: PersId }
}
}
},
pageSize: 10
});
$(document).ready(function () {
$("#letter-list").kendoGrid({
dataSource: ds_LettersGrid,
sortable: true,
filterable: { extra: false, operators: {
string: { startswith: "Starts with", eq: "Is equal to" }
}
},
pageable: true,
columns: [{
field: "BodyText", title: "Letter Content", width: 400, filterable: false
}, {
field: "CreatedBy", title: "Author", filterable: false
}, {
field: "CreatedDate", title: "Original Date", format: "{0:g}", filterable: { ui: "datetimepicker" }
}, {
field: "ModifiedBy", title: "Edited By", filterable: false
}, {
field: "ModifiedDate", title: "Editted On", format: "{0:g}", filterable: { ui: "datetimepicker" }
}, {
command: [ "edit" ], title: "", width: "110px"
}],
height: "300px",
resizable: true,
editable: "popup"
});
});
You need to add default value to your id field , becouse the client side generates new id value, what you already have in server autoincrement generated id value and its shooting error
schema: {
model: {
id: "LetterId",
fields: {
LetterId: {defaultValue: 16000}
BodyText: { editable: true },
CreatedDate: { editable: false, type: "date"},
ModifiedDate: { editable: false, type: "date" },
CreatedBy: { editable: false},
ModifiedBy: { editable: false },
PersonId: { defaultValue: PersId }
}
}
}
I figured it out, it wanted a specific content type. The type being passed was a form, but the controller wanted json. So the Transport now looks like:
update: {
url: '#Url.Action("JsonEditLetter", "Letter")',
dataType: 'json',
>>>>>>>> contentType: "application/json",
type: "POST"
},