I am trying to implement grouping in slickgrid based on the following example.
https://github.com/mleibman/SlickGrid/blob/gh-pages/examples/example-grouping.html
The only difference being I do not have any filter, so I don't call dataview.setFilter()
Below is my grouping code.
#columns =
[
{id: "fname", name: "First Name", field: "firstName", formatter: #formatFname, sortable: true, width: #setWidth(30)}
{id: "lastName", name: "Last Name", field: "lastName", sortable: true, width: #setWidth(30)}
{id: "email", name: "Email ID", field: "email", formatter: #formatEmail, onClick: #launchEmail, sortable: true, width: #setWidth(60)}
]
groupItemMetadataProvider = new Slick.Data.GroupItemMetadataProvider
dataViewOptions = {
groupItemMetadataProvider: groupItemMetadataProvider
inlineFilters: true
}
#dataView = new Slick.Data.DataView(dataViewOptions)
dataView.beginUpdate()
dataView.setGrouping({
getter: 'lastName'
formatter: (g) ->
console.log("g is : ",g)
'Duration: ' + g.value + ' items'
aggregators: []
aggregateCollapsed: false
lazyTotalsCalculation: true
});
dataView.setItems(data)
dataView.endUpdate()
I am even able to see my groups with proper title set to each group.
But I am not seeing any group rows in my slick grid.
You may be using ES6 features that I'm not familiar with, but the code looks suspicious to me, eg
dataView.setGrouping({
getter: 'lastName'
formatter: (g) ->
console.log("g is : ",g)
'Duration: ' + g.value + ' items'
aggregators: []
aggregateCollapsed: false
lazyTotalsCalculation: true
});
There are no commas between the elements of this object definition.
Also, the arrow function does not look correctly formed to me. Since there are two statements, it should be contained in braces and have a return keyword.
Related
I'm with problems trying to edit a cell in slickgrid. I'm still not familiar with slickgrid... I can normally put the data in the grid but I can't edit the cells value. I already set in my options the editable camp as true (editable:true), but still nothing happens when I try to edit. I guess I have to call something else to make the cell editable? Sorry if this question looks stupid, but indeed I'm still a "noob" with slickgrid. Below is my script where I initiate the grid
var grid;
var columns = [
{ id: "Id", name: "Id", field: "Id" },
{ id: "Name", name: "Name", field: "Name", minWidth: 70 },
{ id: "Salary", name: "Salary", field: "Salary" },
{ id: "Address", name: "Address", field: "Address" }
];
var options = {
enableCellNavigation: true,
enableColumnReorder: false,
multiColumnSort: true,
asyncEditorLoading: true,
forceFitColumns: true,
editable: true
};
$(function () {
var myData = [];
$.getJSON('/Home/getEmployeeList', function (data) {
myData = data;
console.log(myData);
grid = new Slick.Grid("#myGrid", myData, columns, options);
});
});
You have to add this
editor: Slick.Editors.Text,
editor: Slick.Editors.LongText
editor: Slick.Editors.Date
editor: Slick.Editors.Checkbox
based on your requirement to a particular cell which needs to be edited
{ id: "Name", name: "Name", field: "Name", minWidth: 70, editor: Slick.Editors.Text},
The best place to start is the examples.
You probably want this one: http://6pac.github.io/SlickGrid/examples/example3-editing.html
I'd advise you to use the 6pac repo, it's up to date. The original mleibman one has not been updated for about four years.
I got similar issue and resolved it by including slick.editors.js.
<script src="slickgrid/slick.editors.js"></script>
I was create kendo grid with sortable: true property and turn off sorting for some columns by setting property sortable to false
this._grid = $('#findResultsGrid').kendoGrid ({
sortable: true,
groupable: {
messages: {
empty: 'drag columns here'
}
},
scrollable: true,
columns:[
{
width: '100px',
title: 'Project',
field: 'PROJECT',
template: '<p style="' + defaultStyle + '">#=PROJECT#</p>'
},
{
width: '100px',
title: 'Well',
field: 'SLHOLENAME',
sortable: false,
template: '<p style="' + defaultStyle + '">#=SLHOLENAME#</p>'
},
...
But some columns without sort disabling (has no option sortable: false) not sortings and looks as not sortable
Sorry, i found my own bug while prepared reproducing example - unsortable columns has not filled field property
Same problem. The field property of a column needs to be set for column sorting to work. Since:
columns.sortable: If set to true the user can click the column header and sort the grid by the column field when sorting is enabled.
Another case of this problem is when you have numerical fields if one of them is 0, it will be considered as not set.
To fix this, prefix an empty string to it to force its conversion to string:
field: '' + item.field,
I have a problem that is confounding me for a few days. Initially, I tested a hard-coded approach within my javascript function which loads local variable containing a simple array as follows:
var myGridData = [
{ ID: "55505", Item: "Mortgage foreclosure", Class: "36", Status: "Pending" },
{ ID: "55506", Item: "Food truck parks", Class: "43", Status: "Pending" }];
for (var i = 0; i <= myGridData.length; i++)
jQuery("#popGrid").jqGrid('addRowData', i + 1, myGridData[i]);
And the above hard-coded approach works. But when I assign the data dynamically to the my GridData variable (based on user selections from another grid, my grid populates with empty rows, one row for each character in the variable (i.e. 154 rows using the above - instead of the two expected). I've double checked the two strings and they are identical (including the correct qualifiers, brackets, etc. so I am at a loss. Any ideas?
Thanks in advance,
Neale
Thanks Oleg, I can look into filling grid during its creation…once I understand everything a bit better. I’m kind of stabbing in the dark. Below, I’ve included code I use to obtain the array data string from the “main” page – which is then passed to the dialog via a hidden field. I’ve followed that up with my JQGrid parameters and colModel:
var temp = document.getElementById('<%=txtArray.ClientID%>').value;
var myGridData = temp;
jQuery("#popGrid").jqGrid({
multiselect: true,
data: myGridData,
datatype: 'local',
colNames: [
'ID',
'Item',
'Class',
'Status',
],
colModel: [
{ name: 'ID', index:'ID', key: true, width:50 },
{ name: 'Item', index: 'Item', key: true, width:100 },
{ name: 'Class', index: 'Class', key: true, width: 150 },
{ name: 'Status', index: 'Status', key: true, width: 250 },
],
multiSort: true,
sortable: true,
loadonce : true,
rownum: 5,
width: 850,
height: 100,
scrollOffset: 1,
shrinkToFit: true,
sortname: 'ID',
viewrecords: true,
gridview: true,
sortorder: "desc",
pager: '#popPager'
});
I have the codes below for example:
$("#grid").kendoGrid({
dataSource: {
data: students,
pageable: false
},
scrollable: true
sortable: true,
selectable: true,
columns: [
{ field: "Name", title: "Name", width: 230},
{ field: "Sex", title: "Sex", width: 50 },
{ field: "Ca", title: "C.A." , width: 55 },
{ field: "TotolScore", title: "Totol Score", width: 100 },
{ field: "Rank", title: "Rank", width: 60 }
]
});
The codes above allows me to do sorting of columns. But I need to do extra special for the "Rank" column. What I want is when I click the column "Rank" it will sort but based on "TotalScore" value.
Is that possible?
Thanks
Yes, it is possible.
When a column is sortable, you can define a compare function and this does not have to compare the same column.
Example: Replace your Rank column definition by this...
{
field: "Rank",
title: "Rank",
width: 60,
sortable : {
compare : function (a, b) {
return a.TotolScore - b.TotolScore;
}
}
}
Here, I define a column that will show the value of Rank but I define my own compare function that is actually working on TotalScore values.
You can check compare documentation for more information.
And check a running example here: http://jsfiddle.net/OnaBai/p2tsupvx/
I want to know if anyone has seen this. I have a kendo grid and in the save event, I want to do some validation. Basically to make sure that the new values difference between the old is less than or equal to the balance.
So if it is greater than the balance, I trigger an alert and preventDefault. However displaying an alert causes the page to reload in FireFox.
Here is my grid:
$("#gridOpenInvoices").kendoGrid({
autoBind: false,
dataSource: openInvoicesData,
scrollable: true,
sortable: false,
navigatable: true,
toolbar: [{name:"save",
text:strings.ApplyUpdates},
{name: "SplitPayment",
text: strings.SplitPayment},
{name: "PaidOut",
text: strings.PaidOut},
{name: "CreateCredit",
text: strings.CreditBalance},
{name: "UndoAllocation",
text: strings.UndoAllocation}],
columns: [
{
field: "CustomerName",
title: strings.AccountName,
hidden: true
},
{
field: "OpenTransactionId",
title: strings.OpenTransaction,
width:90
},
{
field: "InvoiceNumber" ,
title: strings.InvoiceNumber,
width:65
},
{
field: "GrossSales",
title: strings.OriginalAmount,
width: 75,
format: "{0:c}",
decimals: 2,
min: 1,
value: 0
},
{
field: "Balance",
title: strings.TransBalance,
width: 75,
format: "{0:c}",
decimals: 2,
min: 1,
value: 0
},
{
field: "Date",
title: strings.Date,
width:75,
format: "{0:MM/dd/yy}"
},
{
field: "Age",
title: strings.Age,
width:55
},
{
field: "CheckNumber",
title: strings.CheckNumber,
width:85
},
{
title: strings.ApplyPayment,
width:75,
template: "<input class='k-chk-applied chkbox' type='checkbox' data-bind='source: IsApplied' name='IsApplied' #= IsApplied ? 'checked' : ''#/>",
attributes:{"class":"tdIsApplied"}
},
{
field:"AppliedAmount",
title: strings.AppliedAmount,
format: "{0:c}",
width: 95,
attributes: {"class" : "tdAppliedAmount"}
}],
save: function(e) {
var model = e.model;
if (e.values.AppliedAmount != null) {
var remainingBalance = context.getRemainingBalance();
var difference = e.values.AppliedAmount - model.AppliedAmount;
if (remainingBalance >= difference) {
var balanceCopy = model.BalanceCopy;
model.Balance = model.GrossSales - e.values.AppliedAmount;
model.BalanceCopy = model.GrossSales - e.values.AppliedAmount;
if (model.Balance == 0 && model.IsUncollected) {
model.IsUncollected = false;
context.UpdateBalance(balanceCopy, 0, true);
}
context.UpdateBalance(model.AppliedAmount, e.values.AppliedAmount, true);
this.refresh();
context.showButtons();
}
else {
alert("The applied amount exceeds the remaining balance");
e.preventDefault();
}
}
}, editable:"incell"});
This seems to be only happening when you edit the applied amount and hit enter to commit. Any idea of why this is happening?
The solution is fairly simple: Do not use an alert.
I do have the same problem in some events in kendoUI Widgets.
If you need to display something to the user, use kendoWindow with it's modal property set to true.
Alerts should only be used for debugging purposes, like console.log.