How to unlock Kendo-UI Grid multi-column header programmatically - printing

I have a grid with multi-column headers and there is a group column A which is locked. Here is the code:
$scope.gridOptions.columns = [
{
title: "A", locked: true, headerAttributes: { "class": "section-border" }, groupId : "A",
columns: [{ field: "ROW_HEADER", filterable: false, width: "20px", title: " .", sortable: false, locked: true, headerAttributes: { "class": "sub-col darkYellow-col rowHeaderHeadYellow", "style": "border-right: 0px !important;" }, attributes: { "class": "contert-alpha rowHeaderCell" } },
{ field: "COLUMN1", title: "COLUMN1", width: "80px", hidden: true, locked: true, headerAttributes: { "class": "sub-col darkYellow-col rowHeaderHead2" }, attributes: { "class": "" }, template: "#: COLUMN1)#" },
{ field: "COLUMN2", title: "COLUMN2", width: "150px", locked: true, headerAttributes: { "class": "sub-col darkYellow-col rowHeaderHead2" }, attributes: { "class": "" }, template: #:COLUMN2#}
]
},
{
title: "B", headerAttributes: { "class": "section-border" }, groupId: "B",
columns: [{ field: "COLUMN3", title: "COLUMN3", width: "110px", headerAttributes: { "class": "sub-col continuity" }, attributes: { "class": "contert-alpha center-middle" }, template: "#: COLUMN3 #" },
{ field: "COLUMN4", title: "COLUMN4", width: "120px", headerAttributes: { "class": "sub-col no-left-border" }, attributes: { "class": "contert-number " }, format: "{0: MM/dd/yyyy}" },
}]
}]
I want to unlock the group column A programmatically before printing the grid so that it appears as one grid instead of two. I have set locked=false for COLUMN1, COLUMN2 and group column A before printing but it still stays locked. Then I've set only group column A as unlocked before printing and the group still stays locked. I am using recursive method to unlock them but I but in order to show the gist of this functionality I am doing this to unlock:
thisGrid.unlockColumn("A");thisGrid.unlockColumn("ROW_HEADER");thisGrid.unlockColumn("COLUMN1");thisGrid.unlockColumn("COLUMN2");
Where thisGrid is instance of above grid. If anyone has programmatically locked/unlocked multi-column header please help. Thanks

When we are unlocking columns we have to make sure that there is atleast one column left in the grid which is still locked. So in my case I removed ROW_HEADER from the group A and put it independently as the first column, now when I try to unlock column group A it get successfully unlocked.
$scope.gridOptions.columns = [{ field: "ROW_HEADER", filterable: false, width: "20px", title: " .", sortable: false, locked: true, headerAttributes: { "class": "sub-col darkYellow-col rowHeaderHeadYellow", "style": "border-right: 0px !important;" }, attributes: { "class": "contert-alpha rowHeaderCell" } },
{
title: "A", locked: true, headerAttributes: { "class": "section-border" }, groupId : "A", field: "DUMMY_FIELD"
columns: [
{ field: "COLUMN1", title: "COLUMN1", width: "80px", hidden: true, locked: true, headerAttributes: { "class": "sub-col darkYellow-col rowHeaderHead2" }, attributes: { "class": "" }, template: "#: COLUMN1)#" },
{ field: "COLUMN2", title: "COLUMN2", width: "150px", locked: true, headerAttributes: { "class": "sub-col darkYellow-col rowHeaderHead2" }, attributes: { "class": "" }, template: #:COLUMN2#}
]
},
{
title: "B", headerAttributes: { "class": "section-border" }, groupId: "B",
columns: [{ field: "COLUMN3", title: "COLUMN3", width: "110px", headerAttributes: { "class": "sub-col continuity" }, attributes: { "class": "contert-alpha center-middle" }, template: "#: COLUMN3 #" },
{ field: "COLUMN4", title: "COLUMN4", width: "120px", headerAttributes: { "class": "sub-col no-left-border" }, attributes: { "class": "contert-number " }, format: "{0: MM/dd/yyyy}" },
}]
}]
Another issue is that there is no field property defined in grouped column A but we need to either have field property or column index to lock/unlock a column, so I've added field: "DUMMY_FIELD" there and then unlock it successfuly using this code: thisGrid.unlockColumn("DUMMY_FIELD")

First of all, in order for the unlockColumn method to work on the A column group you need to assign it a field property.
The problem is that the Kendo UI Grid documentation states that after initializing the grid with a locked column, at least one column should remain locked at all times.
In your case, You have two main "columns", A and B, and only A is locked.
Therefore when you try to unlock A, it stays locked.
One workaround is to add another column with a zero width and keep it locked at all times.
See a demo here.

Related

Tabulator and Select2, not showing selecte value at load

I want to use Select2 in Tabulator but triggering the selected value does not work.
Here is my code of the formatter for the table column:
{
title: "Select2", field: "lucky_no", align: "center", width: 300, editor: true,
formatter: function (cell, formatterParams, onRendered) {
onRendered(function () {
var select_2 = $(cell.getElement());
select_2.select2({
theme: "classic",
placeholder: 'Select',
data: list,
minimumResultsForSearch: Infinity,
width: 300,
minimumInputLength: 0,
allowClear: true,
}).on('change', function (e) {
console.log('change');
});
select_2.val(list[cell.getValue()].id);
var x = select_2.val();
select_2.val(x).trigger('change');
})
}
},
I have added a working example.
Triggering the selected value works in drop-down above the table.
Although in the table the change event is triggered it does not show the selected value in the dropdown.
Thanks,
Aad
If you are trying to make the field editable, you should be creating a custom editor not a formatter
Formatters are for displaying data to users, editors are for allowing the user to edit the data.
Built In Select Editor
Before I go to far into this example, did you know that Tabulator already comes with a Select Editor built-in to make your life even easier, in the demo in the documentation, have a look at the gender column to see it in action.
Custom Editor
When using custom editors, they come with select and cancel call backs to allow you to pass the data back into the table.
So for your example it should look something like this (this code is untested)
//create custom editor
var select2Editor = function(cell, onRendered, success, cancel, editorParams){
//create input element to hold select
var editor = document.createElement("input");
onRendered(function(){
var select_2 = $(editor);
select_2.select2({
theme: "classic",
placeholder: 'Select',
data: list,
minimumResultsForSearch: Infinity,
width: 300,
minimumInputLength: 0,
allowClear: true,
});
select_2.on('change', function (e) {
success(select_2.val());
});
select_2.on('blur', function (e) {
cancel();
});
});
//add editor to cell
return editor;
}
//in your column definition for the column
{title: "Select2", field: "lucky_no", align: "center", width: 300, editor: select2Editor},
My first question .. this was not included!
var tabledata = [{
id: 1,
name: "Oli Bob",
progress: 12,
location: "United Kingdom",
gender: "male",
rating: 1,
col: "red",
dob: "14/04/1984",
car: 1,
lucky_no: 3
},
{
id: 2,
name: "Mary May",
progress: 1,
location: "Germany",
gender: "female",
rating: 2,
col: "blue",
dob: "14/05/1982",
car: true,
lucky_no: 2
},
{
id: 3,
name: "Christine Lobowski",
progress: 42,
location: "France",
gender: "female",
rating: 0,
col: "green",
dob: "22/05/1982",
car: "true",
lucky_no: 5
},
{
id: 4,
name: "Brendon Philips",
progress: 100,
location: "USA",
gender: "male",
rating: 1,
col: "orange",
dob: "01/08/1980",
lucky_no: 7
},
{
id: 5,
name: "Margret Marmajuke",
progress: 16,
location: "Canada",
gender: "female",
rating: 5,
col: "yellow",
dob: "31/01/1999",
lucky_no: 4
},
];
var list = [{
"id": 1,
"text": "Organisatorische tekortkomingen"
}, {
"id": 2,
"text": "Mechanische gevaren"
}, {
"id": 3,
"text": "Hijs-/hefgevaren"
}, {
"id": 4,
"text": "Ergonomische tekortkomingen"
}, {
"id": 5,
"text": "Mobiliteit en gevaarlijke situaties"
}, {
"id": 6,
"text": "Elektrische gevaren"
}, {
"id": 7,
"text": "Blootstelling aan gevaarlijke stoffen"
}, {
"id": 8,
"text": "Gevaarlijke situaties - Algemeen"
}, {
"id": 9,
"text": "Blootstelling aan straling"
}, {
"id": 10,
"text": "Druk"
}, {
"id": 11,
"text": "Blootstelling aan trillingen"
}, {
"id": 12,
"text": "Blootstelling aan geluid"
}, {
"id": 13,
"text": "Fysieke gevaren (overig)"
}, {
"id": 14,
"text": "Gevaar voor/door derden (hijsen/heffen)"
}, {
"id": 15,
"text": "Hijsen/heffen en ergonomische tekortkomingen"
}, {
"id": 16,
"text": "Mobiliteit en werkplek/bestuurdersplaats"
}, {
"id": 17,
"text": "Mobiliteit en ergonomische tekortkomingen"
}, {
"id": 18,
"text": "Mobiliteit en energiebron en -overbrenging"
}, {
"id": 19,
"text": "Mobiliteit en stabiliteit"
}, {
"id": 20,
"text": "Gevaarlijke situaties door onverwachte opstart/beweging"
}, {
"id": 21,
"text": "Gevaren beheerst!",
"scope": "Algemeen"
}, {
"id": 22,
"text": "NIET beoordeeld!"
}];
$('#selectList').select2({
data: list,
minimumResultsForSearch: Infinity,
width: 'resolve',
minimumInputLength: 0,
allowClear: true,
placeholder: "Select",
});
$('#selectList').val(7).trigger('change');
//Build Tabulator
var table = new Tabulator("#example-table", {
height: "500px",
columns: [{
title: "Name",
field: "name",
width: 150
},
{
title: "Location",
field: "location",
width: 130
},
{
title: "Progress",
field: "progress",
sorter: "number",
align: "left",
formatter: "progress",
width: 140
},
{
title: "Gender",
field: "gender",
editor: "select",
editorParams: {
"male": "Male",
"female": "Female"
}
},
{
title: "Rating",
field: "rating",
formatter: "star",
align: "center",
width: 100
},
{
title: "Date Of Birth",
field: "dob",
align: "center",
sorter: "date"
},
{
title: "Driver",
field: "car",
align: "center",
formatter: "tickCross"
},
{
title: "Select2",
field: "lucky_no",
align: "center",
width: 300,
//editor: true,
formatter: function(cell, formatterParams, onRendered) {
onRendered(function() {
var select_2 = $(cell.getElement());
select_2.select2({
theme: "classic",
placeholder: 'Select',
data: list,
minimumResultsForSearch: Infinity,
width: 300,
minimumInputLength: 0,
allowClear: true,
}).on('change', function(e) {
//console.log('change');
});
select_2.val(list[cell.getValue()].id);
var x = select_2.val();
select_2.val(x).trigger('change');
})
}
},
],
});
//load sample data into the table
table.setData(tabledata);
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" rel="stylesheet" />
<link href="https://unpkg.com/tabulator-tables#4.1.3/dist/css/tabulator.min.css" rel="stylesheet" />
<link href="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.6-rc.0/css/select2.min.css" rel="stylesheet" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js"></script>
<script src="https://unpkg.com/tabulator-tables#4.1.3/dist/js/tabulator.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.6-rc.0/js/select2.min.js"></script>
<html>
<body>
<div>
<select class="form-control" name="selectList" id="selectList">
</select>
</div>
<br />
<div id="example-table" class="table-striped table-bordered"></div>
</body>
</html>

how can i do to not lose a filter in a jqxGrid when a change the next page? i'm using the filters from my dataAdapter

i have a problem, i use this control is a jqxGrid, this is:
function initGridUsuarios() {
// campos y adaptador
var fields = [
{ name: "NoEmpleado", type: "int" },
{ name: "Nombre", type: "string" },
{ name: "Departamento", type: "string" }
],
dataAdapter = utils.generateGridAdapter(gridEmpleados, "GestionPaqueteInfo", "ObtenerGridUsuarios", fields, getGridFilters);
gridEmpleados.jqxGrid({
width: 900,
height: 400,
theme: tema,
columnsresize: true,
pageable: true,
altrows: true,
virtualmode: true,
rendergridrows: function () {
return dataAdapter.records;
},
localization: utils.getIdiomaGrid(),
source: dataAdapter,
columns: [
{ text: "Id", dataField: "Id", columngroup: "Titulo", width: 100, hidden: true },
{ text: "Número de Empleado", dataField: "NoEmpleado", columngroup: "Titulo", width: 150 },
{ text: "Nombre", dataField: "Nombre", columngroup: "Titulo", width: 250 },
{ text: "Departamento", dataField: "Departamento", columngroup: "Titulo", width: 350 },
{
text: "Crear paquete info", datafield: "Crear", columngroup: "Titulo", columntype: "button", width: 150, cellsrenderer: function () {
return "Crear";
}, buttonclick: function (clickRow) {
crear();
}
},
],
columngroups: [
{ text: "Busqueda de Empleados para creación de paquete inventario informática", align: "center", name: "Titulo" }
]
});
}
actually it loose the filter, when i change the page, what can i do to not lose the filter?
:$ sorry my english is not really good :$:$

angular ui-grid how to add filters and data

I have a ui-grid project I am trying for the first time. I am trying to add BOTH my data and my gridOptions.
To get the gridOptions to work I need to do
<div id="grid1" ui-grid="gridOptions" class="grid"></div>
To get the $scope.data to work I need to do
<div id="grid1" ui-grid="{data: myData}" class="grid"></div>
How do I get both the gridOptions and myData in the ui-grid div?
Here is my controller:
.controller('ListCtrl', function ($scope, $state, ServerRequest, $localStorage, $sessionStorage, uiGridConstants) {
var vm = this, c = console;
$scope.myData = [
{
"alert": "10",
"firstName": "Jon",
"lastName": "Smith",
"DOB": "09/30/1987",
"sex": "M",
"MI": "A",
"referralReason": "Eye Exam",
"status": "Rescheduled",
"time": "9:00AM",
"homeNum": "416-555-5555",
"cellNum": "905-555-5555",
"notes": "awesome"
},
{
"alert": "9",
"firstName": "Jane",
"lastName": "Doe",
"DOB": "02/22/1927",
"sex": "F",
"MI": "A",
"referralReason": "Diabetic Seizure",
"status": "Rescheduled",
"time": "10:00AM",
"homeNum": "416-555-5555",
"cellNum": "905-555-5555",
"notes": "cool"
},
{
"alert": "6",
"firstName": "James",
"lastName": "Brooke",
"DOB": "02/30/1888",
"sex": "M",
"MI": "F",
"referralReason": "Corneal Crestocopy",
"status": "Rescheduled",
"time": "11:00AM",
"homeNum": "416-555-5555",
"cellNum": "905-555-5555",
"notes": "awesome"
}
];
//this formats the row
$scope.highlightFilteredHeader = function( row, rowRenderIndex, col, colRenderIndex ) {
if( col.filters[0].term ){
return 'header-filtered';
} else {
return '';
}
};
//this code handles the sort functions of each column
$scope.gridOptions = {
enableFiltering: true,
onRegisterApi: function(gridApi){
$scope.gridApi = gridApi;
},
columnDefs: [
{
field: 'alert', headerCellClass: $scope.highlightFilteredHeader
},
{
field: 'firstName', headerCellClass: $scope.highlightFilteredHeader
},
{
field: 'lastName', headerCellClass: $scope.highlightFilteredHeader
},
{
field: 'DOB', headerCellClass: $scope.highlightFilteredHeader
},
{
field: 'referralReason', headerCellClass: $scope.highlightFilteredHeader
},
{
field: 'status', headerCellClass: $scope.highlightFilteredHeader
},
{
field: 'time', headerCellClass: $scope.highlightFilteredHeader
},
{
field: 'homeNum', headerCellClass: $scope.highlightFilteredHeader
},
{
field: 'cellNum', headerCellClass: $scope.highlightFilteredHeader
},
{
field: 'MI', headerCellClass: $scope.highlightFilteredHeader
},
{ field: 'sex', filter: {
term: '1',
type: uiGridConstants.filter.SELECT,
selectOptions: [ { value: '1', label: 'male' }, { value: '2', label: 'female' }, { value: '3', label: 'unknown'}, { value: '4', label: 'not stated' }, { value: '5', label: 'a really long value that extends things' } ]
},
cellFilter: 'mapGender', headerCellClass: $scope.highlightFilteredHeader },
{
field: 'notes', headerCellClass: $scope.highlightFilteredHeader
},
]
};
})//end of controller
//this is for the gender filter as it has inline options
.filter('mapGender', function() {
var genderHash = {
1: 'male',
2: 'female'
};
return function(input) {
if (!input){
return '';
} else {
return genderHash[input];
}
};
})
}());
to reiterate. if I just use ui-grid="gridOptions, i only see the header row of the grid with the filter options. If I just use ui-grid={data:myData} then I see the entire table, but without the ability to filter - I just want to see both
In your controller, you can assign your data to $scope.gridOptions.data.

Bind data to grid after page load MVC

I have problem here.With kendo grid i'm loading data from some action in controller.But in the last column i have link which should fire another action in same controller.When i delete this piece of code
type: "json",
transport: {
read: {
url: "#Html.Raw(Url.Action("ListFinances", "Jobs"))",
type: "POST",
dataType: "json",
data: additionalData
},
},
schema: {
data: "Data",
total: "Total",
errors: "Errors"
},
last column is working perfect,bit when is present this piece of code, last column is not working>please here some help, i;m new to mvc.Below is the code:
$("#jobs-grid").kendoGrid({
dataSource: {
data: #Html.Raw(JsonConvert.SerializeObject(Model.FinishedJobs)),
schema: {
model: {
fields: {
JobNumber: { type: "string" },
CustomerId: { type: "number" },
JobCount: { type: "number" },
JobYear: { type: "number" },
Status: { type: "number" },
Position: { type: "number" },
Finished: { type: "boolean" },
HasInvoice: { type: "boolean" },
}
}
},
type: "json",
transport: {
read: {
url: "#Html.Raw(Url.Action("ListFinances", "Jobs"))",
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: 20,
serverPaging: true,
serverFiltering: true,
serverSorting: true
},
//dataBound: onDataBound,
columns: [
#*{
field: "Status",
title: "Status",
template: '#= Status #'
},*#
{
field: "JobNumber",
title: "jobNumber",
template: '#= JobNumber #'
},
{
field: "CustomerId",
title: "Customer",
template: '#= Customer.Name #'
},
{
field: "Id",
title: "Id"
},
#*{
field: "ShortDesc",
title: "ShortDesc"
},*#
{
field: "DateCompletition",
title: "DateCompletition"
},
{
field: "Id",
title: "#T("Common.Edit")",
width: 130,
template: 'Edit'
}
],
pageable: {
refresh: true,
pageSizes: [5, 10, 20, 50]
},
editable: {
confirmation: false,
mode: "inline"
},
scrollable: false,
// sortable: true,
// navigatable: true,
// filterable: true,
// scrollable: true,
selectable: true
});
});
</script>
It seems you want to add a command to the grid, The way to add a command as described here is as follows
var grid = $("#jobs-grid").kendoGrid({
dataSource: {
pageSize: 20,
data: #Html.Raw(JsonConvert.SerializeObject(Model.FinishedJobs)),
},
pageable: true,
height: 550,
columns: [
{ field: "JobNumber", title: "JobNumber", width: "140px" },
{ field: "CustomerId", title: "Customer", width: "140px" },
{ field: "Id", title:"Id" },
{ field: "DateCompletition", title:"DateCompletition" },
{ command: { text: "Edit",
click: function(e){
// here you can add your code
}},
title: " ",
width: "180px" }]
}).data("kendoGrid");
You might have a look on the documentation of the kendo grid here
Hope this will help you

Extjs Grid Paging Toolbar Shows All Data and No Page Number

I am using extjs paging toolbar on my grid. I have pagesize 5, but it shows all data(default is I guess 25)... but when I click next page, it still shows the first 25 data. and also have issue with page number where it's blank of 2...when it's suppose to say 1 of 2... Click here to see what it looks like
this is my grid...
var myPageSize = 5;
store.load({
params: {
start: 0,
limit: myPageSize
}
});
this.grid = Ext.create('Ext.grid.Panel', {
title: 'GridView App',
store: store,
loadMask: true,
columns: [{
header: 'Q1',
sortable: true,
dataIndex: 'Q1',
flex: 1,
}, {
header: 'Q2',
sortable: true,
dataIndex: 'Q2',
flex: 1,
}, {
header: 'Q3',
sortable: true,
dataIndex: 'Q3',
flex: 1,
}, {
header: 'Q4',
sortable: true,
dataIndex: 'Q4',
flex: 1,
}, {
header: 'Improvements',
flex: 1,
sortable: true,
dataIndex: 'Improvements'
}, {
header: 'Comments',
flex: 1,
sortable: true,
dataIndex: 'Comments'
}],
bbar: Ext.create('Ext.PagingToolbar', {
style: 'border:1px solid #99BBE8;',
store: store,
displayInfo: true,
preprendButtons: true,
displayMsg: 'Displaying Surveys {0} - {1} of {2}',
emptyMsg: "No Surveys to display"
}),
stripeRows: true,
trackover: true,
renderTo: Ext.getBody()
});
and this is my store
var store = Ext.create('Ext.data.JsonStore', {
storeId: 'myData',
scope: this,
fields: [{
name: 'Q1',
type: 'int'
}, {
name: 'Q2',
type: 'int'
}, {
name: 'Q3',
type: 'int'
}, {
name: 'Q4',
type: 'int'
}, {
name: 'Q5',
type: 'int'
}, {
name: 'Improvements',
type: 'string'
}, {
name: 'Comments',
type: 'string'
}],
sorters: [{
property: 'Q1',
direct: 'ASC'
}],
proxy: {
type: 'ajax',
url: 'GridView/writeRecord',
reader: new Ext.data.JsonReader({
root: 'myTable',
totalProperty: 'count'
})
}
});
And my Json looks like this, please click here
UPDATE JSON RESULT
{
"count": 30,
"myTable": [
{
"Q1": "1",
"Q2": "1",
"Q3": "1",
"Q4": "1",
"Improvements": "",
"Comments": "1"
},
{
"Q1": "1",
"Q2": "2",
"Q3": "3",
"Q4": "4",
"Improvements": "Iphone5",
"Comments": "Iphone14"
},
{
"Q1": "1",
"Q2": "1",
"Q3": "3",
"Q4": "3",
"Improvements": "This is Comment1-3",
"Comments": "This is Comment2-3"
},
The issue is with the data you're returning from server. With that store configuration you must return a json formatted like this (note that records fields are different that yours)
{
"success" : true,
"count" : 2,
"myTable" :[{
"id" : 1,
"cod" :"100001"
},{
"id" : 2,
"cod" :"100001"
}]
}
Store's root parameter is where extjs expects to have the array of records, success parameter is something you can handle to display server comunication errors and totalProperty is where you tell to extjs how many total records you have fetched. (Answer based on extjs 4.x, but as i can remember with 3.x is the same)

Resources