Using custom ellipsis for truncated text in Tabulator - tabulator

I use Tabulator component and I need replace regular ellipsis (...) with custom.
Then I want add click event for them. Main idea - user can click on custom ellipsis (or glyph) and for him will be shown modal window with full text and a copy button.
Most browsers don`t support custom string as ellipsis, so I cant use CSS property.
I think I can add some glyph using Tabulator formatter functionality and handle click on this glyph, but in this case I got another problem: "how check text is truncated".
Please give advice with this - custom ellipsis in Tabulator cell.

You would need to use a Custom Formatter to achieve this.
because formatter functions are called before the element is added to the DOM you will need to use the onRendered callback passed into the function to trigger the display of the ellipsis if the cell is overflowing once it is drawn:
//custom formatter
var ellipsisFormatter = function(cell, formatterParams, onRendered){
onRendered(function(){
var element = cell.getElement();
if(element.scrollWidth > element.clientWidth){
//add ellipsis
}else{
//hide ellipsis
}
});
return cell.getValue();
});
//column definition
{title:"Name", field:"name", formatter:ellipsisFormatter},

Related

How to change tabulator Pagination buttons text and position

First part of the question is I want to simply change the original buttons "First", "Prev" and so on to some other text.
here is a link that shows original btns.
My second part of the question is how can i display the pagination in a footer out side the table
such as:
<table></table>
<div class:"footer">
pagination
</div>
There are several options you can use to change the pagination setup
Button Text
If you are looking to change the text, then the localisation system allows you to change any text for any part of the table, for full details see the Localization Documentation
var table = new Tabulator("#example-table", {
locale:"en-gb",
langs:{
"en-gb":{
"pagination":{
"page_size":"Page Size", //label for the page size select element
"first":"First", //text for the first page button
"first_title":"First Page", //tooltip text for the first page button
"last":"Last",
"last_title":"Last Page",
"prev":"Prev",
"prev_title":"Prev Page",
"next":"Next",
"next_title":"Next Page",
},
}
},
});
Button Position
If you simply want to change the position of the pagination element within the footer you can use CSS. The Styling Documentation contains a full list of classes used for styling the pagination elements.
To move the elements to the left hand side of the footer for example you would ned to use the following CSS:
.tabulator .table-footer{
text-align:left;
}
External Footer Element
if you want Tabulator to put the pagination elements into an element outside of the table, then you just need to pass the query selector for the element into the footerElement property in the table constructor. The Footer Layout Documentation contains full details on this.
In the example below i am assuming you have an element outside the table with an id of "my-footer" that you want the elements to appear in:
var table = new Tabulator("#example-table", {
footerElement:"#my-footer",
});
Here is the first part of the question:
$(".tabulator-paginator").find($(".tabulator-page[title='Next Page']")).text('>');
$(".tabulator-paginator").find($(".tabulator-page[title='Last Page']")).text('>>');
$(".tabulator-paginator").find($(".tabulator-page[title='First Page']")).text('<');
$(".tabulator-paginator").find($(".tabulator-page[title='Prev Page']")).text('<<');
As far as the second part tabulator have to keep the footer inside the table for it's javascript(the one the does pagination) to work. Hopefully in future updates it would let us do that, as it would provide more ability to custom the css.

Tabulator. How to enable and disable editing from js

I'm using tabulator (fantastic thing), which has a built in, in line editing functionality.
The thing is though, it's either on or off by having the editor tag on a column basis.
You can disable the editor for a given cell as well.
What I'm trying to do is to have the table displayed as read only so to say.
Then click on a 'edit' button (which is in my table and I capture the click). That would in turn enable the inline, built-in editor functionality for that raw only.
Then I click a save button, write the updated data back to my DB and make the row read-only again.
So, with tabulator 4.2, I'd be looking for something like
var usrtable = new Tabulator("#usrtable", {
ajaxURL:"/account/cgi-bin/getallusers.php",
resizableColumns:false,
tooltips:true,
history:true,
pagination:"local",
paginationSize:10,
paginationSizeSelector:true,
reactiveData:true,
selectable:true,
initialSort:[{column:"username", dir:"asc"},],
columns:[
{ formatter: editIcon, width: 40, sortable: false, align: "center", cellClick: function (e, cell) {
var id = cell.getRow().getData().id;
row(id).editable=true;
/\/\/\/\/\/\/\/\/\/\/\
}
},
{title:"Id", field:"id", visible:false},
{title:"Username", field:"username", width:80, editor:"input"},
{title:"Password", field:"password", width:70, editor:"input"},
{title:"Role", field:"role", width:70, align:"center", formatter:"plaintext", editor:"select", editorParams:{values:["user","admin"]}},
{title:"Change passwd", field:"changepasswd", width:90, align:"center", formatter:"tickCross", sorter:"boolean", editor:true},
],
});
Is that somehow possible or do I have to re-invent the wheel? i.e. create a model to edit the data outside the table?
What I have tried.....
Once rendered, a cell looks like this:
<div class="tabulator-cell" role="gridcell" tabulator-field="username" tabindex="0" title="test" style="width: 80px; height: 29px;">test</div>
And when you click on the cell, it becomes editable and the class 'tabulator-editing' is added to the div.
So..... I though I could 'just' catch the click event and do something like this:
$(".tabulator-cell").on("click",function(){
($this).removeClass("tabulator-editing");
});
that didn't work so tried this:
$(".tabulator-cell").on("click",function(e){
e.preventDefault();
});
that didn't work either.
When doing this:
$(".tabulator-cell").on("click",function(){
alert("cell clicked");
});
it actually never fires... :-(
Either I'm doing something wrong or really do not know where to go from here....
This can be achieved with Tabulator's Optional Editing:
// column definition
{ title:"Name", field:"name", editor:"input", editable:editCheck }
var editCheck = function (cell) {
var isEditable = cell.getRow().getElement().classList.contains('isEditable');
return isEditable;
}
With this logic in place, you simply need to toggle isEditable class on the appropriate Tabulator Row.
In the documentation under Column Setup, there is a Data Manipulation option called editable.
http://tabulator.info/docs/4.2/columns#definition
editable - callback to check if the cell is editable (see Manipulating Data for more details)
I haven't experimented with it myself, but it appears as if this is only called when initially rendering the table, so you may have to force a re-render with table.redraw(true) when the user clicks the Edit and Save buttons.
You could also just use your cellClick event and call cell.edit().
So, I also got feedback from Oli who is the developer for Tabulator.
The short answer is that there is no option to enable editing at the row lever as I feared.
Furthermore, the option will not be added due to multiple factors.
In other words, what I'm trying to do is not available out of the box and the editing is to be done at the cell level.
There is no option for this in the tabulator. But if you want to disable a cell from editing, you can simply remove all the tabulator applied classes for the particular cell. For eg., if you want to make the last row edit disabled, you can use something like this,
$(".tabulator-row:last .tabulator-cell").removeAttr("role tabulator-field tabindex title");
I know this is a old question but my answer can be useful for visitors come here (like me) in future..
We have also a similar requirements, and we ended up by this solution. We have added "editor" in every column with another attribute "editable". In "editable", we are checking whether the row is selected or not, if row is selected then field can be editable otherwise not editable.
Other than that we have also used a "rowSelected" and "rowDeselected" to show/hide save button and on "rowSelected", we are checking that only 1 row is selected at a time.

How do I compute the Selected property of a BasicLeafNode for a Dynamic Content Control - Updated 03/26/2014

I have created an XPage with the following: Started by creating a custom layout control using the Application Layout. I aded the layout control to the xpage and then dropped in a Dynamic Content Control. I configured the control as follows:
<xe:dynamicContent id="dynamicContent1" defaultFacet="GovernanceReviews"
useHash="true">
<xp:this.facets>
<xc:ccViewDocumentTemplates xp:key="DocumentTemplates"></xc:ccViewDocumentTemplates>
<xc:ccViewGovProcurementReviews xp:key="GovProcurementReviews"></xc:ccViewGovProcurementReviews>
<xc:ccViewGovRevReporting xp:key="GovRevReporting"></xc:ccViewGovRevReporting>
<xc:ccViewGovRevWOCompleted xp:key="GovRevWOCompleted"></xc:ccViewGovRevWOCompleted>
<xc:ccViewGovernanceReviews xp:key="GovernanceReviews"></xc:ccViewGovernanceReviews>
<xc:ccViewProfilesByType xp:key="ProfilesByType"></xc:ccViewProfilesByType>
<xc:ccViewProfilesWithTargetCompl xp:key="ProfilesWithTargetCompl"></xc:ccViewProfilesWithTargetCompl>
<xc:ccViewLastUpdated xp:key="LastUpdated"></xc:ccViewLastUpdated>
<xc:ccViewUserGuide xp:key="UserGuide"></xc:ccViewUserGuide>
<xc:ccViewTracking xp:key="Tracking"></xc:ccViewTracking>
</xp:this.facets>
</xe:dynamicContent>
Then I dropped in a navigator control in the left column and created BasicLeafNodes to correspond to the dynamic content control I used the href property and used the #content="" to display the correct content.
This works just fine, but I am having problems figuring out how to make the selections in the navigator highlight when they are selected. I know I need to compute the Selectd property,but I can't figure out how to get the xp:key value so I can compare it to the SubmitValue. I know this is probably something simple, but I can't figure it out.
Can someone please enlighten me.
Thanks,
MJ
ADDED 03/26/2014 - I have a feeling that it has something to do with Using the href property of the Dynamic Content Control to perform the content switching. I know that makes the BasicLeafNodes Links. So, not sure how the Navigator records which link is being executed and how to capture that.
MJ
Add a value is the submitValue property
And in the onItemClick Event
Assign the submitted value to a viewScope variable
viewScope.Selected=context.getSubmittedValue()
And finally check if the viewScope variable equals your item submit value in the selected property. This needs to be calculated
if(viewScope.Selected="byCategory"){
return true
}else{
return false
}
The following is working for me:
if(viewScope.Selected == "byCategory"){
return true
} else{
return false
}
An equality test must be made with two equal symbols (or three). One equal symbol evidently always returns true.
I did it by jQuery. Just put the following code to the custom control, which contains navigator.
$( function() {
if (window.location.hash.length > 0) {
select()
}
});
$(window).on('hashchange', function() {
select();
});
function select() {
$(".lotusColLeft .lotusMenu .lotusBottomCorner li").removeClass(
"lotusSelected")
$(".lotusColLeft .lotusMenu .lotusBottomCorner li a")
.filter(
function() {
return window.location.hash.indexOf($(this).attr(
'href')) > -1
}).parent().addClass("lotusSelected")
}

How to style a specific list item in lwuit?

I am need of a requirement that in a list, some of the list item should exhibit different style than others. How can this be achieved in lwuit?
For Example,
List menu = new List();
menu.addItem("1. Green");
menu.addItem("2. Red");
menu.addItem("3. Blue");
In this list Each item should have the style of representing its color(i.e) Green should have green Background and Red should have Red Background. Is it possible in LWUIT? How can we achieve this?
Thanks in Advance.
You must create a cell renderer for this use case. Just derive 'DefaultListCellRenderer' e.g.:
DefaultListCellRenderer rend = new DefaultListCellRenderer() {
public Component getCellRendererComponent(Component list, Object model, Object value, int index, boolean isSelected) {
Component c = super.getCellRendererComponent(...);
c.getStyle().setBgTransparency(255);
c.getStyle().setBgColor(theColorYouWant);
return c;
}
};
Then set this renderer to the list. You will probably need some additional refinements here since this is a WAY oversimplified example of a renderer.
This is one way of doing it.
1. Create a component for each item in the list
2. Add the bg color and text to it.
3. Once done, add it to a form or any other custon component you have created.
Other way:
You can create your own List renderer. Here is some information on how you can do it

Setting value of a Radio Button Group Client Side

I need to set the value of a Radio Button Group that has two possible values. I'm able to accomplish this with SSJS, but having issues setting it via CSJS. Any help is appreciated.
I use something like this:
function setRadioValue(value)
{
var elements = document.getElementsByName ("#{id:radioGroup1}");
for(i=0;i<elements.length;i++) {
if (elements[i].value == value) {
elements[i].checked = true;
}
}
}
Then you can just call setRadioValue("This is teh value of the Radio Button I want to set")
Thanks
You need to get the the server-side generated name of the radio button group using the #{id:} method. Example:
var radioButtonGroup = XSP.getElementById("#{id:radioButtonGroupName}");
You can then use client-side Javascript to manipulate the radioButtonGroup element. I believe you need to loop over the radio buttons in the elements until you find the radio button with the desired value. You can then set its checked value to true.

Resources