Disable/remove close icon on Kendo Grid's default group column - kendo-grid

I am using Kendo UI Grid for one of my solutions. I have this one task/requirement where I should be able to give a default grouping for the grid, and the user should not be able to remove this grouping from the UI.
There is one way of achieving this as in this jsFiddle example: http://jsfiddle.net/siva_hari/xzLfgsba/4/
If you look at the following example, the grouping is true but the grouping can be changed by clicking on k-group-delete icon or by dragging the grouped column back into the grid.
http://jsfiddle.net/siva_hari/xzLfgsba
group: [{field: "ShipName"}],
groupable: false
But there is one one problem with this solution, you do not have the group header(because the groupable is set to false) and you cannot sort based on the group it self.
Is there a way to show group header and also disable further changes to grouping of the grid?
Thank you.

Disabling the close handle (X button) is simple, just hide it. I can hide it programmatically but using CSS is much more effective.
span.k-icon.k-group-delete{
display:none;
}
Next step is to get rid of the draggable property of the grouping indicator. To do this, we destroy the draggable container. We need to do this after dataBound because the grid properties are re-applied every time dataBound is called.
dataBound:function(e){
setTimeout(function(){
//get the indicator header
var groupIndicatorHeader = $('.k-group-indicator').parent();
if(!groupIndicatorHeader) return;
//check if it is draggable eneabled
var kendoDraggableObj = $(groupIndicatorHeader).data('kendoDraggable');
if(kendoDraggableObj) kendoDraggableObj.destroy();
},0);
}
setTimeout is necessary to make it run after all dataBound and natural kendo code has finished running. Here is the fiddle for this solution.
You will probably notice that this solution is very hacky, and it is. But sometimes you just gotta roll with it to get the customization you need.

Related

Clear selection for Kendo Grid in Angular 2

I've got an application that allows a user to select a row in a Kendo Angular 2 grid and click a button that removes that row. After the row is removed, however, the grid selection persists on the index of the row that was just removed. I'd like to clear the grid's selection after the button is clicked and the row is removed. For the life of me, I cannot find a way to do this. Any ideas?
The Kendo Grid control has a property of "selectedKeys" which binds to an array of numbers. You can then clear this array when you want to clear the selection of the grid.
<kendo-grid
[selectedKeys]="mySelection"></kendo-grid>
In your code:
this.mySelection = [];

How to show/hide certain JTable columns based on selection in JComboBox

I have a JTable and a JComboBox. I want certain columns to hide when I select one item in the combobox and the same hidden columns to reappear when I select the other item in the combobox. I write,
jTable1.getColumnModel().getColumn(8).setMinWidth(0)
jTable1.getColumnModel().getColumn(8).setMaxWidth(0)
jTable1.getColumnModel().getColumn(8).setWidth(0)
for hiding the column, but when I again write
jTable1.getColumnModel().getColumn(8).setMinWidth(100)
jTable1.getColumnModel().getColumn(8).setMaxWidth(100)
jTable1.getColumnModel().getColumn(8).setWidth(100)
the hidden columns do not become visible.
Reason is that both setMin/setMax enforce the relation
min <= width <= max
That is the order of method calling matters
// hiding
column.setMinWidth(0);
column.setMaxWidth(0);
// showing
column.setMaxWidth(100);
column.setMinWidth(100);
Note that you need not call setWidth, that's handled internally.
That said: forcing the sizes is .. a hack. Consider using a clean solution, f.i. a framework like SwingX which has (amongst other niceties :-) full-fledged support for column hiding
Use JTable#removeColumn and JTable#addColumn. These operations only affect the view side, not the model side
what's a problem in above code?
In addition to kleopatra's helpful insight, documented here, some L&Fs are more or less cooperative. For example, com.apple.laf.AquaLookAndFeel always leaves enough width to drag after setMinWidth(0), although the column can be forced to zero width manually.
for (int i = 0; i < 2; i++) {
jTable1.getColumnModel().getColumn(8).setMinWidth(100)
jTable1.getColumnModel().getColumn(8).setMaxWidth(100)
jTable1.getColumnModel().getColumn(8).setWidth(100)
}
The columns will become visible.

User-friendly, Form input that always totals 100

I have a dynamically generated form that needs to gather several numerical values from a user that totals 100 (%). I thought about writing a script/algorithm that adjusts the remaining values of several text fields - so that when the user changes one value, the remaining values dynamically change (so that the values always total 100).
However, instead of text fields, I would really prefer something more user-friendly like sliders that move when one slider is adjusted or some other user-friendly widget (like an adjustable pie chart(?) that always totals 100%).
The script needs to work in late version of Firefox, Chrome and IE. I read somewhere that HTML5 sliders don't work in Firefox.
I am open to different solutions.
Am not getting your question clearly, assuming that you need a value slider which a person will slide and automatically the bar will increment every time by 1, so try using jQuery and Ajax, will suit your requirements, you can check out few over here.
Sliders work fine in FireFox - try http://www.colorpicker.com/
You can use the jQuery UI slider, if you like. You can register a custom function on change event which easily adjusts the other sliders.
So in the end you got something like this (some pseudo-code in it):
$( "#slider1" ).slider({
change: function(event, ui) {
var i = 100 - value_of_slider1 / number_of_sliders_remaining;
$("#slider2).setValue(i);
$("#slider3).setValue(i);
}
});
Of course this can be implemented a lot more sophisticated. Just to give you the basic idea. Depends on your markup.
I have not had problems with sliders in FireFox.
You can have the various sliders/input devices calculate on each other to get the output by division or whatever, then have the last/smallest number be subtracted rather than divided from the total. This way your other calculations will be accurate to the accuracy and the least significant value can make up the rest.

Show itemRenderer in specific DataGrid rows... others empty

I have a DataGrid populated via an Array. The last column in the DataGrid uses an ItemRenderer (Button). I want to show the Button in certain rows but not in others (leave those empty). I've looked everywhere for an example or even a clue how to do this (tried labelFunction on DG, etc.) but can't find anything about it. Any help would be appreciated. Thanks!
Okay... with (lots of) help, figured it out.
First off, I'm not sure why the itemRenderer requires a container but it does. The array must also be checked from the itemRenderer and not from the main application... again, I don't know why since the debugger shows it going through the exact same loop/events, etc.).
If interested here's the relevant parts of the code:
Main App:---
{col1:'', col2:'', col3:'', col4:'', col5:'', col6:'', col7: '', col8:'', col9:'', col10:'', col11:'yo'}];
public function initData():void
{ xferSchedule.dataProvider = schedArray; }
]]>
an item renderer does not have to be a container, it has to implement IDataRenderer (a Button does not). One could extend Button and implement this interface to get a simple button renderer. If you want it to display conditionally, you will accomplish this by handling those conditions within the renderer based on the data.
Now this might get slightly complex. I would recommend you to define you an XML instead of Array of Objects. If the node has the type property button, then it would create button at that cell whose value type is button.
How to create a button dynamically inside a grid which is yet again dynamic?
This might end into the whole component being dynamic.

What's the best way to hide a tab in a TabNavigator?

I'd like to conditionally hide a tab in a TabNavigator. It seems that setting visible doesn't work properly (presumably because this is how the TabNavigator hides the tabs that aren't currently selected).
What's the right way to do this?
You can do this by making use of TabNavigator's getTabAt() method which returns the Button that makes up the visual tab. You can then set that Button's visible property. It's a little tricky to get this setup with a bindings, but it's doable.
You could also consider just disabling the tab instead, which you can do by setting enabled on the corresponding TabNavigator child (for which visible didn't work).
What do you mean by hide? If you actually mean remove, then just take your array that's bound to the data in the TabNavigator, and remove the applicable element from it.
If you want to just have them removed temporarily, create a component of your own that encapsulates the TabNavigator and has an array of removed tabs and an array of actual tabs. Then handle this as you see fit.
You might want to check out the flexlib project. They have a component called SuperTabNavigator that adds a lot of functionality to the base Flex TabNavigator, including hiding tabs (I think).
If you do have to create your own component, though, it's a bit more tricky. The thing to know is that "tabs" are actually specially styled buttons, contained within a TabBar component (the TabBar is then contained within the TabNavigator). What you'll have to do then, is subclass TabNavigator and have some property on your views (i.e. the canvases, etc. that are added to the TabNavigator) that is bound to the visible and includeInLayout properties of the TabBar buttons.
In essence, what you'll have is something like:
BindingUtils.bindProperty( tabButton, "visible", view, "someProperty" );
BindingUtils.bindProperty( tabButton, "includeInLayout", view, "someProperty" );
I don't know about TabNavigator, but in other containers, you can set the includeInLayout property to false and it will be ignored. You probably still need to combine it with visible.
var secondTab = tabNavigator.removeChildAt(0);