Knockout-Kendo.js editableTemplate - asp.net

I am using Knockout-Kendo.js in Durundal.js
How do I bind Custom editable.template or call custom HTML when click on Edit and Add buttons.
I have tried the below code but not working
<div data-bind="kendoGrid: { data: items, editableTemplate: 'editTemplate', useKOTemplates: true }"> </div>
<script id="editTemplate" type="text/html">
<h3>Edit User</h3>
<p>
<label>User Name:<input data-bind="text:username" /></label>
</p>
</script>
Viewmodel.js file for knockout binding
define(['services/logger', 'config', 'services/dataservice'], function (logger, config, dataservice) {
var title = 'Users';
var items = ko.observableArray();
var vm = {
items: items,
activate: activate,
title: title
};
return vm;
//#region Internal Methods
function activate() {
dataservice.getUsers(vm.items);
ko.bindingHandlers.kendoGrid.options = {
dataSource: {
schema: {
model: {
fields: {
firstName: { type: "string" },
lastName: { type: "string" },
username: { type: "string" },
company: { type: "string" },
addressLine1: { type: "string" },
addressLine2: { type: "string" },
city: { type: "string" },
state: { type: "string" },
postCode: { type: "string" },
phoneNumber: { type: "string" },
website: { type: "string" },
vatNumber: { type: "string" },
registrationNumber: { type: "string" },
creadtedBy: { type: "string", editable: false, nullable: true, hidden: true },
createdOn: { type: "date", editable: false, nullable: true, hidden: true },
modifiedBy: { type: "string", editable: false, nullable: true, hidden: true },
modifiedOn: { type: "date", editable: false, nullable: true, hidden: true },
}
}
},
pageSize: config.gridPageSize
},
toolbar: config.gridToolbar,
height: config.gridHeight,
columns: [
{ field: "firstName", title: "First Name", width: "90px" },
{ field: "lastName", title: "Last Name", width: "90px" },
{ field: "company", title: "Company", width: "90px" },
{ field: "username", title: "User Name", width: "90px" },
{ field: "addressLine1", title: "Address Line1", width: "90px" },
{ field: "addressLine2", title: "Address Line2", width: "90px" },
{ field: "city", title: "City", width: "90px" },
{ field: "state", title: "State", width: "90px" },
{ field: "postCode", title: "Post Code", width: "90px" },
{ field: "phoneNumber", title: "Phone Number", width: "90px" },
{ field: "website", title: "Website", width: "90px" },
{ field: "vatNumber", title: "Vat Number", width: "90px" },
{ field: "registrationNumber", title: "Registration Number", width: "90px" },
{ field: "creadtedBy", title: "Created By", width: "130px" },
{
field: "createdOn",
title: "Created On",
width: "130px",
format: "{0:MM/dd/yyyy HH:mm tt}",
filterable: {
ui: "datetimepicker"
}
},
{ field: "modifiedBy", title: "Modified By", width: "130px" },
{
field: "modifiedOn",
title: "Modified On",
width: "130px",
format: "{0:MM/dd/yyyy HH:mm tt}",
filterable: {
ui: "datetimepicker"
}
},
{ command: ["edit", "destroy"], title: " ", width: "160px" }
],
editable: config.gridEditableType
};
}
//#endregion
});

Related

Kendu Grid - Function inside row template always undefined

I am trying to use a custom row template on my grid so i can give various class declarations to individual cells in the grid.
The function i am trying to call to return the string for the css class is always undefined, no matter where i declare it.
This is the code for my grid declaration file:
(function(){
'use strict';
var logPrefix = 'sampleRequestTrackingGrid --> ';
var rowTemplateString =
'<tr data-uid="#= uid #">' +
'<td>#: requestedBy #</td>' +
'<td>#: site #</td>' +
'<td>#: sampleLot#</td>' +
'<td>#: sampleProcess #</td>' +
'<td>#: workOrderId #</td>' +
'<td>#: equipmentId #</td>' +
'<td>#: area #</td>' +
'<td>#: cell #</td>' +
'<td>#: station #</td>' +
'<td>#: testMethods #</td>' +
'<td>#: requestedDate #</td>' +
'<td class="#: getStatus(requestStatus) #">#: requestStatus #</td>' +
'<td>#: requestStatusMsg #</td>' +
'<td>#: requestId #</td>' +
'</tr';
function getStatus(requestStatus){
if(requestStatus === 'In Queue'){
return 'inQueue';
}
else if(requestStatus === 'In Progress'){
return 'inProgress';
}
else if(requestStatus === 'Complete'){
return 'complete';
}
else if(requestStatus === 'Failed'){
return 'failed';
}
}
angular.module('wm.sampleRequestTracking')
.constant('SampleRequestTrackingGrid', {
options: function(model){
return {
dataBound: model.onGridDataBound,
dataSource: {
data: model.gridData,
schema: {
model: {
id: "requestSysI",
fields: {
requestSysI: {editable: false},
requestedBy: {editable: false},
site: {editable: false},
sampleLot: {editable: false},
sampleProcess: {editable: false},
workOrderId: {editable: false},
equipmentId: {editable: false},
area: {editable: false},
cell: {editable: false},
station: {editable: false},
testMethods: {editable: false},
requestedDate: {editable: false, type: "datetime"},
requestStatus: {editable: false},
requestStatusMsg: {editable: false},
requestId: {editable: false}
}
}
},
pageSize: 200
},
scrollable: true,
resizable: true,
reorderable: true,
pageable: true,
groupable:true,
filterable: true,
autobind: false,
columnMenu: true,
navigatable: true,
selectable: true,
sortable: {mode: "multiple"},
columns: [
{field: "requestedBy", title: "Requested By", width: "100px", hidden: false},
{field: "site", title: "Site", width: "100px", hidden: false},
{field: "sampleLot", title: "Lot", width: "100px", hidden: false},
{field: "sampleProcess", title: "Process", width: "100px", hidden: false},
{field: "workOrderId", title: "Work Order", width: "100px", hidden: false},
{field: "equipmentId", title: "Equipment", width: "100px", hidden: false},
{field: "area", title: "Request Area", width: "100px", hidden: false},
{field: "cell", title: "Request Cell", width: "100px", hidden: false},
{field: "station", title: "Request Station", width: "100px", hidden: false},
{field: "testMethods", title: "Test Methods", width: "100px", hidden: false},
{field: "requestedDate", title: "Request Date", width: "100px", hidden: false},
{field: "requestStatus", title: "Request Status", width: "100px", template: "<span id='reqStatus'>#=requestStatus#</span>"},
{field: "requestId", title: "Request Id", width: "100px", hidden: false}
],
rowTemplate: rowTemplateString
};
}
});
})();
Assuming everything was working correctly, I would change the background color of the classes using the following CSS inside a .less file
.inQueue {
background-color: white;
}
.inProgress {
background-color: #fda;
}
.complete {
background-color: #ced;
}
.failed {
background-color: #fdd;
}
But, every time i run the code and try to load the grid i get an error telling me that getStatus() function is not defined.
Can anyone offer some assistance in figuring out what i am doing wrong here?
For reference: the Telerik article i was following is
https://docs.telerik.com/kendo-ui/controls/data-management/grid/how-to/Layout/style-rows-cells-based-on-data-item-values
I ended up not using a row template, as i realized it was a little unnecessary and too complex for what i needed, and instead modified my field template.
Also, as #Soham commented, placing the getStatus function outside the IIFE did work. I had done that previously, but perhaps it was because of my typo on the tr that it failed before.
(function(){
'use strict';
var logPrefix = 'sampleRequestTrackingGrid --> ';
angular.module('wm.sampleRequestTracking')
.constant('SampleRequestTrackingGrid', {
options: function(model){
return {
dataBound: model.onGridDataBound,
dataSource: {
data: model.gridData,
schema: {
model: {
id: "requestSysI",
fields: {
requestSysI: {editable: false},
requestedBy: {editable: false},
batteryId: {editable: false},
site: {editable: false},
sampleLot: {editable: false},
sampleProcess: {editable: false},
workOrderId: {editable: false},
equipmentId: {editable: false},
area: {editable: false},
cell: {editable: false},
station: {editable: false},
testMethods: {editable: false},
requestedDate: {editable: false, type: "datetime"},
requestStatus: {editable: false},
requestStatusMsg: {editable: false},
requestId: {editable: false}
}
}
},
pageSize: 200
},
scrollable: true,
resizable: true,
reorderable: true,
pageable: true,
groupable:true,
filterable: true,
autobind: false,
columnMenu: true,
navigatable: true,
selectable: true,
sortable: {mode: "multiple"},
columns: [
{field: "requestedBy", title: "Requested By", width: "100px", hidden: false},
{field: "batteryId", title: "Battery", width: "100px", hidden: false},
{field: "site", title: "Site", width: "100px", hidden: false},
{field: "sampleLot", title: "Lot", width: "150px", hidden: false},
{field: "sampleProcess", title: "Process", width: "150px", hidden: false},
{field: "workOrderId", title: "Work Order", width: "100px", hidden: false},
{field: "equipmentId", title: "Equipment", width: "100px", hidden: false},
{field: "area", title: "Request Area", width: "100px", hidden: false},
{field: "cell", title: "Request Cell", width: "100px", hidden: false},
{field: "station", title: "Request Station", width: "100px", hidden: false},
{field: "testMethods", title: "Test Methods", width: "100px", hidden: false},
{field: "requestedDate", title: "Request Date", width: "100px", hidden: false},
{field: "requestStatus", title: "Request Status", width: "100px", template: "<div class='#=getStatus(requestStatus)#' id='reqStatus' style='text-align: center'>#=requestStatus#</div>"},
{field: "requestId", title: "Request Id", width: "100px", hidden: false}
]
};
}
});
})();
function getStatus(requestStatus){
if(requestStatus === 'In Queue'){
return 'inQueue';
}
else if(requestStatus === 'In Progress'){
return 'inProgress';
}
else if(requestStatus === 'Complete'){
return 'complete';
}
else if(requestStatus === 'Failed'){
return 'failed';
}
}
With the end result being:
screenshot of column

UI-Grid: columns resizing ends in overflowing the grid

I have a grid that consists of several columns. I defined columnDefs including width and min width. In addition I have disabled the horizontal scrollbar.
When resizing the columns to the right they "exit" the grid and I can see them by scrolling (although there is no scroll). How can I force the columns to stay in the grid boundaries?
This is the regular view:
After resizing to the right and scrolling to the right, you can see that the "name" column is off boundaries (on the left side)
Grid Config
columnDefs: this.queueConfig.columns,
rowHeight: 24,
rowTemplate: rowtpl,
enableHorizontalScrollbar: this.uiGridConstants.scrollbars.NEVER,
enableColumnMenus: false,
enableRowSelection: true,
enableRowHeaderSelection: false,
enableFiltering: true,
modifierKeysToMultiSelect: true,
multiSelect: true
Column Definitions
This is a function that returns the columnDefs for the grid.
The details are not important, only to notice the width definition for our issue.
private buildGridColumns(): any {
const colMinWidth = "100";
const columnsMap = {
name: {
name: this.$translate.instant('Name'),
field: "documentName",
minWidth: colMinWidth
},
step: {
name: this.$translate.instant('Col_Step'),
field: "status",
width: "150",
minWidth: colMinWidth,
cellFilter: "printStatus"
},
submitted: {
name: "Submitted",
field: "createdTime",
width: "150",
minWidth: colMinWidth,
cellFilter: "date: 'd/M/yy h:mm a'",
sort: {
direction: this.uiGridConstants.DESC
}
},
pagesNum: {
name: this.$translate.instant('NumPages'),
field: "numPages",
width: "80",
minWidth: colMinWidth,
cellFilter: "foreignDocument: this"
},
quantity: {
name: this.$translate.instant('Quantity'),
field: "numCopies",
width: "80",
minWidth: colMinWidth,
cellFilter: "foreignDocument: this"
},
progress: {
name: "Progress",
field: "PercentComplete",
minWidth: colMinWidth,
cellTemplate:
"<kd-progress-bar ng-if='!row.entity.isForeign' percentage='row.entity.percentComplete'></kd-progress-bar>" +
"<div ng-if='row.entity.isForeign' class='kd-progress-unavailable'>N/A</div>"
},
duration: {
name: this.$translate.instant('Duration'),
field: "estimatedTime",
minWidth: colMinWidth,
cellFilter: "foreignDocument: this"
},
status: {
name: this.$translate.instant('Status'),
field: "docState",
minWidth: colMinWidth,
cellFilter: "documentState"
},
press: {
name: this.$translate.instant('Press'),
field: "dfeName",
minWidth: colMinWidth
},
created: {
name: this.$translate.instant('Created'),
field: "createdDtm",
minWidth: colMinWidth,
cellFilter: "date: 'd/M/yy h:mm a'",
sort: {
direction: this.uiGridConstants.DESC
}
},
time: {
name: this.$translate.instant("Time"),
field: "createdTime",
minWidth: colMinWidth,
cellFilter: "date: 'd/M/yy h:mm a'",
width: "120",
sort: {
direction: this.uiGridConstants.DESC
}
},
failTime: {
name: this.$translate.instant('FailureTime'),
field: "lastUpdateTime",
minWidth: colMinWidth,
cellFilter: "date: 'd/M/yy h:mm a'",
width: "120",
sort: {
direction: this.uiGridConstants.DESC
}
},
completeTime: {
name: this.$translate.instant('CompletionTime'),
field: "lastUpdateTime",
minWidth: colMinWidth,
cellFilter: "date: 'short'",
width: "120",
sort: {
direction: this.uiGridConstants.DESC
}
}
};
return columnsMap;
}

Switch View on button click in secha touch 2.4.2

I already searched for this question for like more than 100 times and it´s always the same answers, but it doesn´t help me. So my question is:
How can I switch the views by click on a button in sencha touch 2?
I have 2 views:
first
Ext.define('Meet_Me.view.Menue', {
extend: 'Ext.Container',
alias: 'widget.Menue',
layot: 'card',
xtype: 'menue',
requires: [],
config: {
xtype: 'container',
layout: 'vbox',
centered: true,
items: [
{
xtype: 'container',
layout: 'hbox',
items: [
{
xtype: 'button',
text: 'Erstellte Events anzeigen',
width: 300,
height: 100,
margin: '30 5 5 30',
id: 'button1',
},
{
xtype: 'button',
text: 'Event erstellen',
width: 300,
height: 100,
margin: '30 5 5 30',
id: 'event_erstellen_button'
}
]
},
{
xtype: 'container',
layout: 'hbox',
items: [
{
xtype: 'button',
text: 'Event suchen',
width: 300,
height: 100,
margin: '30 5 5 30',
id: 'event_suchen_button'
},
{
xtype: 'button',
text: 'Teilnehmende Events anzeigen',
width: 300,
height: 100,
margin: '30 5 5 30',
badgeText: 'New',
id: 'teilnehmende_events_button'
}
]
},
{
xtype: 'container',
layout: 'hbox',
items: [
{
xtype: 'button',
text: 'Profil',
width: 350,
height: 100,
margin: '30 5 5 30',
//centered: true,
id: 'profil_button'
}
]
}
]
}
});
The important thing here is the Button with the id: 'button1'
The second view:
Ext.define('Meet_Me.view.Login', {
extend: 'Ext.Container',
alias: 'widget.Login',
xtype: 'login',
layot: 'card',
requires: [
'Ext.Panel',
'Ext.field.Email',
'Ext.field.Password',
'Ext.Button',
'Ext.Label'
],
config: {
items: [
{
title: 'Login',
xtype: 'panel',
itemId: 'homePanel',
layout: 'fit',
items: [
{
xtype: 'panel',
itemId: 'loginPanel',
//centered: true,
//margin: '5% 30% 0% 10%',
items: [
{
items: [
{
xtype: 'emailfield',
width: '70',
label: 'Email',
placeHolder: 'email#example.com'
},
{
xtype: 'passwordfield',
width: '70',
label: 'Passwort',
placeHolder: 'min. 6 Zeichen'
},
]
},
{
xtype: 'button',
id: 'loginButton',
margin: 20,
padding: 8,
text: 'Anmelden'
},
{
xtype: 'button',
itemId: 'registerButton',
margin: 20,
padding: 8,
text: 'Registrieren'
}
]
},
{
xtype: 'panel',
hidden: true,
itemId: 'welcomePanel',
items: [
{
xtype: 'label',
//centered: true,
html: 'Welcome!',
itemId: 'welcomeLabel'
}
]
}
]
}
]
}
});
and the Controller:
Ext.define('Meet_Me.controller.Main', {
extend: 'Ext.app.Controller',
requires: [
'Meet_Me.view.Login',
'Meet_Me.view.Menue',
],
config: {
touchstarttime: 0,
control: {
'#button1': {
tap: 'btn1click'
}
}
},
btn1click: function (button, e, options) {
console.log('Button 1 was clicked');
Ext.Viewport.add({
xtype: 'Login'
});
}
});
The problem is that the Login is shown but the first view with the 4 buttons is still there. How do get the first view removed?
you can use Ext.Viewport.animateActiveItem()
If you want to use 'card' layout, setActiveItem() is change items.
See following fiddle.
https://fiddle.sencha.com/#fiddle/16hu

Kendo UI grid row filter move filter operator icon position

I have a grid with very small columns with row filter, which cause them to have very small text-box. so I used
field: "OrderID",
width: 100,
filterable: {
cell: {
inputWidth: 65
}
}
but when I define inputWidth to enlarge the text field the filter operator does not move over and in fact cover up the partial space of the text-box. Therefore, I was wondering if there is a way to move the filter operator over or preferably over to the title header, like the columnMenu filter icon. Any help would be greatly appreciated, thanks.
I took the following example from: http://demos.telerik.com/kendo-ui/grid/filter-row
and modified width and inputwidth of orderID
<div id="example">
<div id="grid"></div>
<script>
$(document).ready(function() {
$("#grid").kendoGrid({
dataSource: {
type: "odata",
transport: {
read:"http://demos.telerik.com/kendo- ui/service/Northwind.svc/Orders"
},
schema: {
model: {
fields: {
OrderID: { type: "number" },
Freight: { type: "number" },
ShipName: { type: "string" },
OrderDate: { type: "date" },
ShipCity: { type: "string" }
}
}
},
pageSize: 20,
serverPaging: true,
serverFiltering: true,
},
height: 550,
filterable: {
mode: "row"
},
pageable: true,
columns:
[{
field: "OrderID",
width: 100,
filterable: {
cell: {
inputWidth: 65
}
}
},
{
field: "ShipName",
width: 500,
title: "Ship Name",
filterable: {
cell: {
operator: "contains"
}
}
},{
field: "Freight",
width: 255,
filterable: {
cell: {
operator: "gte"
}
}
},{
field: "OrderDate",
title: "Order Date",
format: "{0:MM/dd/yyyy}"
}]
});
});

jqgrid rowattr not applying class

I want to apply background color to row of jqGrid row based on value of column, however the basic rowattr is not applying class to rows.
Below is the code (for simplicity I have removed the condition on which color needs to be applied)
jQuery("#employeeSalarysGrid").jqGrid({
height: 250,
url: 'http://localhost:50570/api/Test/Get',
mtype: "GET",
contentType: "application/json; charset=utf-8",
datatype: "json",
serializeGridData: function (postData) {
return JSON.stringify(postData);
},
jsonReader: {
root: function (obj) { return obj; },
page: function (obj) { return 1; },
total: function (obj) { return 1; },
records: function (obj) { return obj.length; },
id: "0",
cell: "",
repeatitems: false
},
datatype: "json",
colNames: ['Id', 'Bank Name', 'Bank Name', 'Employee name', 'Joining date', 'Salary amount', 'Comments'],
colModel: [
{ name: 'Id', align: "center", hidden: true },
{ name: 'BankName', index: 'BankName', align: 'center', editable: false },
{
name: 'BankId', index: 'BankId', align: "center", hidden: true, required: true,
viewable: true, editrules: { edithidden: true, required: true },
editable: true,
edittype: 'select',
editoptions: {
dataUrl: '/api/Test/GetBanks',
buildSelect: function (data) {
var response = jQuery.parseJSON(data);
var s = '<select>';
if (response && response.length) {
for (var i = 0, l = response.length; i < l; i++) {
var bank = response[i];
s += "<option value=" + bank.BankId + ">" + bank.Name + "</option>";
}
}
return s + "</select>";
}
}
},
{ name: 'EmployeeName', align: "center", editable: true, editrules: { required: true } },
{ name: 'JoiningDate', align: "center", editable: true, editrules: { custom: true, custom_func: datecheck },
formatter: 'date', formatoptions: { srcformat: 'y-m-d', newformat: 'd-M-y' }, edittype: 'text', editable: true,
editoptions: { dataInit: function (el) { setTimeout(function () { $(el).datepicker({ dateFormat: 'd-M-y' }); }, 200); } }
},
//{ name: 'cdate', index: 'cdate', width: 80, align: 'right', formatter: 'date', srcformat: 'yyyy-mm-dd', newformat: 'm-d-Y', edittype: 'text', editable: true, editoptions: { dataInit: function (el) { setTimeout(function () { $(el).datepicker(); }, 200); } } },
{ name: 'SalaryAmount', align: "center", editable: true, editrules: { required: true } },
{ name: 'Comments ', align: "center", editable: true }
],
gridview: true,
autoencode: true,
ignorecase: true,
loadonce: true,
sortname: "InstallmentDate",
sortorder: "asc",
viewrecords: true,
rowNum: 10,
rowList: [10, 15, 20],
pager: '#employeeSalarysPager',
caption: "Employee Salary list",
rowattr: function (rd) {
return { "class": "rowClass" };
//alert("hi");
}
});
CSS style :
<style type="text/css">
.rowClass { color: blue; background-image: none;}
</style>
Note: If I uncomment //alert statement, it shows alert message 5 times. It means rowattr is getting invoked for each row, however css class is not getting applied.
Regards,
Abhilash
The rowattr do works correctly, but if you want that the class will be applied on selected rows too then you should change CSS rule to the following
.ui-widget-content .rowClass { color: blue; background-image: none; }
see the demo.

Resources