how to disable a particular column using handsontable in handsontable - handsontable

How to disable a particular column using handsontable in handsontable.I want first column only editable other three columns get disable.I'm using readonly true for three columns but it's not work how to disable....
columns: [
{
type:'handsontable',
handsontable: {
colHeaders: ['EmployeeNo','EmployeeName','Department','Designation'],
data: manufacturerData,
columns:[{},{readOnly: true},
{
readOnly: true
},
{
readOnly: true
}]
}
},
{}]

In Project i do it with this line of codes.
cells : function(row, col, prop) {
var cellProperties = {};
if (col > 0) {
cellProperties.readOnly = true;
}
else
{
cellProperties.readOnly = false;
}
return cellProperties;
}
You can find working example of it on given link. but give example is for set a row to readonly. http://handsontable.com/demo/conditional.html

Your code is working properly. Please see JSFiddle with approach similar to you.
$("#test").handsontable({
startRows: 1,
startCols: 1,
rowHeaders: true,
colHeaders: true,
minSpareCols: 0,
minSpareRows: 0,
contextMenu: false,
fillHandle: false,
outsideClickDeselects: false,
removeRowPlugin: false,
currentRowClassName: 'currentRow',
currentColClassName: 'currentCol',
columnSorting: true,
colHeaders: ['Col1','Col2','Col3','Col4'],
columns: [{},
{readOnly: true},
{readOnly: true},
{readOnly: true}]
});
Working link : http://jsfiddle.net/rvd61fuy/
Let me know, if you are facing anyother issue.

To disable you could make the cell/column readonly and maybe even set the background color to a grey(to give a special effect).Both the methods i.e the one where you use readonly:true in the column declaration when initializing the handsontable and also the one where you use cell properties and use conditions to determine if you need to set a cell to read only when the table is being rendered,both methods seem to be working for me.You need to instantiate your HOT correctly, that may be the problem. Also when using cell properties you needn't use cellProperties.readOnly = false as by default the cells are not read only unless you have coded for that seperately. If you need further assistance let me know.

Also check that you have the latest version of handsontable. I ran into problems trying to implement readonly on cells which had checkbox columns with erratic results.
Using the version below solved my issues (below is what I used in my HTML page)
<script src="http://docs.handsontable.com/pro/1.9.0/bower_components/handsontable-pro/dist/handsontable.full.min.js"></script>
<link type="text/css" rel="stylesheet" href="http://docs.handsontable.com/pro/1.9.0/bower_components/handsontable-pro/dist/handsontable.full.min.css">

Related

In my Datatable, I have a simple column containing only simple strings but it's not sorting correctly

I have a really simple Datatable. Every columns are sorting correctly except one. This columns contain only text (string).
Here's the order I get when I sort the column:
À publier,
Retiré temporairement,
Retiré - Rejet
Nouveau.
Here's the code for the Datatable, as you can see, it's quite simple.
var peutModifier = $('#hdnPeutModifier').val();
if (peutModifier !== 'undefined' && peutModifier === 'True') {
colonneAvecTriDesactive = [0, -1]; // Tri désactivé sur première et dernière colonne.
} else {
colonneAvecTriDesactive = [-1]; // Tri désactivé sur dernière colonne.
}
$('#DataTablePublication').DataTable({
search: false,
bFilter: false,
pageLength: 100,
lengthMenu: [[10, 20, 50, 100], [10, 20, 50, 100]],
columnDefs: [
{ orderable: false, targets: colonneAvecTriDesactive }
],
order: [],
language: {
paginate: {
first: "Premier",
last: "Dernier",
next: "Suivant",
previous: "Précédent"
}
}
});
I checked and the column contains only strings, also, I have not set any trigger on the column sorting and I don't have any errors in my browser.
Does someone have an idea about this problem?
This looks like you have sorted your column in reverse alphabetical order - which is why À appears first (since À follows z, using default codepoint sorting).
To use language-sensitive sorting, i.e. the sort order that you would expect to find in a dictionary (where église follows eagle, not zebra), you can use the DataTables internationalization plug-in.
Steps to use:
Add the library to the <head> section of your page. You can use a CDN for this:
<script src="https://cdn.datatables.net/plug-ins/1.11.0/sorting/intl.js"></script>
Initialize the plug-in in your script, before you create your DataTable:
$.fn.dataTable.ext.order.intl();
You can also provide an explicit locale if you want to:
$.fn.dataTable.ext.order.intl('fr');
There are various additional configuration options described here.

jqgrid number formatter with separator and scale values

Using the number formatter like below to format the JQgrid number with decimalSeparator(,)& decimalPlaces(2)
formatter: 'number', formatoptions :{decimalSeparator: ',', decimalPlaces:2}
after enter the value as 134,56 in grid it was showing as 'NaN'.
please help me how to resolve this issue.
The easy way to display correct the number in case you save to database is to set reloadAfterSubmit to true in navigator or in editGridRow method like this
$("#jqGrid").navGrid("#jqGridPager",{ edit: true, add: true },
// edit options
{ reloadAfterSubmit : true },
// add options
{ reloadAfterSubmit : true }
);

Implementing Search Feature with ngHandsontable

I'm using handsontable on an angular app with ngHandsontable. I can see that I need to set search to true in the table settings, which should make a query method available.
Can someone explain how I am able to access that method through my angular controller?
<input class="" id="handsonSearch" placeholder="Search..." ng-model="searchQuery" />
<hot-table settings="tableSettings.settings"
datarows="mappingData"
col-headers="true"
height="700">
<hot-column data="Column1" title="'Column One'"></hot-column>
</hot-table>
Angular
function GlobalMappingController($scope) {
$scope.tableSettings = {
settings: {
contextMenu: true,
colHeaders: true,
dropdownMenu: true,
afterChange: afterChange,
beforeChange: beforeChange,
search: true,
query: $scope.searchQuery
}
};
The issue is access to the root handsOnTable instance created by ngHandsOnTable isn't as intuitive as you might think, but in order to access all the functions handsOnTable has by itself you have to do something like this.
First, declare the variable we'll use as the instance of the table
$scope.handsOnTable;
You can access the root for handsOnTable by setting the afterInit parameter in the settings array
$scope.tableSettings = {
settings: {
contextMenu: true,
colHeaders: true,
dropdownMenu: true,
afterChange: afterChange,
beforeChange: beforeChange,
search: true,
query: $scope.searchQuery,
//insert this
afterInit: function() {
$scope.handsOnTable = this;
}
}
};
You can then set an ng-change on the input to something like this:
function search() {
$scope.handsOnTable.search.query($scope.searchQuery);
$scope.handsOnTable.render();
}
You'll also need to, in the same manner as the afterInit, set afterchange with the same statement. If you've got your own custom version of the function then just put it in after everything else has ran.
Keep in mind you'll have to keep the input box bound to searchQuery and add onChange="search()" but that should work - at least it did for me.

How to display jqPivot Group header in Orderby

Here is the Example created - Pivot Table JSFiddle example: here
groupingView: {
groupField: ['ComponentType'],
groupColumnShow: [false],
groupDataSorted: true,
groupOrder: "desc"
}, /*Is not working properly, when i click sort on ComponentType, group headers are not sorting*/
Need help to display ComponentType(group header) in desc order.
Thanks
First of all you have to fix the grouping options options which you use. You have to use
groupOrder: ["desc"]
instead of
groupOrder: "desc"
The main problem with ignoring of "desc" grouping order exist already in old version of jqGrid (see the line of jqGrid 4.6 and the line of jqGrid 4.7).
I fixed the code in free jqGrid. The demo which uses the latest version of free jqGrid from GitHub don't have more the described problem: https://jsfiddle.net/OlegKi/bkqce0s0/11/
If you have to use old version of free jqGrid of jqGrid then you can solve the problem by changing datatype from "jsonstring" to "local":
onInitGrid: function () {
var p = $(this).jqGrid("getGridParam"),
userdata = p.datastr.userdata;
// filter the data and remove some items
p.data = $.grep(p.datastr, function (item) {
return item.ComponentType !== "";
});
p.userData = userdata;
p.datatype = "local";
}
The demo http://jsfiddle.net/OlegKi/bkqce0s0/12/

jQuery dataTables : Clicking thead should sort descending and then ascending for all columns

I am trying to change the default sorting direction. The default order is ascending and then descending. I am trying to reverse it.
The sorting direction should be independent and should apply to all the columns( Number of columns vary with different tables ) The script I have to initiate datatable is generic.
Sorting should only apply on click.
I found few examples but they are column specific https://datatables.net/examples/advanced_init/sort_direction_control.html
Here is my script
jQuery(function($) {
$(".datatable").dataTable({
"paging": false,
"searching": false,
"info": false,
"orderCellsTop": true
});
});
All options and settings has default values defined in the internal DataTable.defaults object. This object is available for altering through $.fn.dataTable.defaults. This is poorly documented on the website, but very well documented in the code. Open a none minified jquery.dataTables.js and search for DataTable.defaults.
To reverse the default ordering for all columns, so it becomes desc, asc :
$.fn.dataTable.defaults.column.asSorting = ['desc', 'asc'];
To set the initial ordering for the first column to desc
$.fn.dataTable.defaults.aaSorting = [[0,'desc']];
Likewise you can simply alter the defaults so you not need to set any generic options in your dataTable() at all :
$.fn.dataTable.defaults.bPaginate = false; //paging: false
$.fn.dataTable.defaults.bFilter = false; //searching: false
$.fn.dataTable.defaults.bInfo = false; //info: false
$.fn.dataTable.defaults.bSortCellsTop = true; //orderCellsTop: true
see demo -> http://jsfiddle.net/f31pncb4/
You can do it while initializing:
jQuery(function ($) {
$(".datatable").dataTable({
"paging": false,
"searching": false,
"info": false,
"orderCellsTop": true,
aoColumnDefs: [
{
orderSequence: ["desc", "asc"],
aTargets: ['_all']
}
]
});
});
Richard's answer above works but is the legacy approach. The syntax for current versions is similar and a bit simpler:
var myTable = $('table').DataTable({
"columnDefs": [
{
"orderSequence" : [ "desc", "asc" ],
"targets" : "_all"
}
]
});
Slightly off topic but note capital "D" in DataTable() which returns an api instance instead of a jquery object. This is important since doing it this way allows you easier access to the api after initialization.
Extending the #Eaten by a Grue's answer, if we want, we can use the same orderSequence API to reverse the sort order using HTML only.
Under the <thead>, we can change the <th> as follows:
<th data-order-sequence='[ "desc", "asc" ]'>Amount</th>

Resources