Bootstrap-table: Prepopulate Column-Select button: a few selected, most unselected - javascript

I want to render a bootstrap-table page, and the dataset has quite a few columns. However on page-load I want to show only a few (2 or 3) columns, but have the other columns "in reserve".
Here is a GUI mockup to show what I mean:
Collapsed
Button Expanded:
Here I have clicked on "Toogle all" to deselect all, then selected the first 3 manually.
I'd like to have the 3 selected on page load. Is there alaready a setting or an option that I can use to acheive this?
Users should see a simple table, and only power-users will click on the button and add more, then do horizontal scrolling, change column selections etc

Answering my own question, because I cannot really revoke or delete it.
This question is a duplicate of "https://stackoverflow.com/questions/41446362/hide-columns-in-bootstrap-table-at-startup/41488928#41488928" from 2017 .
There question has a few alternative answers already.
For my use-case it was sufficient to follow the accepted answer. It recommends to put these HTML data-attributes into the tr of the thead element:
<td data-visible="false" ...>
This is the simplest solution and works well for small tables, and if you have absolute control over the table-generation- and column-selection process.
Columns disabled this way will still be available with the "Select columns" button created with data-show-columns="true" and data-show_columns-toggle-all="true".
It might not work so well in more complicated scenarios, e.g. when you need to access the hidden columns via the DOM. For details see "https://stackoverflow.com/questions/41446362/hide-columns-in-bootstrap-table-at-startup/41488928#41488928"

Related

SAPUI5 StandardListItem sort by selected

I have SelectDialog for one of the popovers. Inside that, I am displaying data using StandardListItem.
The list shows more than 2000 records. However, it takes lots of time to load data, so I set the threshold of 50. When user opens popover, it will show the first 50 records, once he scrolls down, next set of 50 records and so on.
Now, the issue is when user search for a record (e.g. "ABC"), this ABC can be at position 500 in the list. He selects ABC, closes popover, and then reopens it, he cannot see ABC (because ABC is not in first 50 records). He needs to scroll down 6 times to see the data.
What I want to achieve, is once the user selects records, it automatically goes to the top position. UI5 SelectDialog (UI5 Demo Kit) does not provide this functionality since it only supports one-way binding. Any help on this?
My fragement.XML code:
<SelectDialog
id="idSel"
growingThreshold="50"
growing="true"
showClearButton="true"
items="{data>AllItems}"
multiSelect="true"
noDataText="Not Found"
liveChange="handleSearch"
title="Choose"
autoAdjustWidth="true"
growingScrollToLoad="true">
<StandardListItem id="idItem" description="{data>AllDataId})"
title="{data>Title}" type="Active"/>
</SelectDialog>
rememberSelections would keep the options ticked/unticked but "ABC" would still be in position 500. I don't think the standard sap.m.SelectDialog control has a way of doing this.
I see a few options though:
If the selection is queried from somewhere (OData?) you could enrich the options read with whether they are selected or not for this purpose. Then add a sorter to the list that sorts by selected first (https://sapui5.hana.ondemand.com/#/api/sap.ui.model.Sorter). You might also be able to do that in the UI when reading the list data at once, but you've already said you're doing that in batches for performance reasons.
If manipulating the backend won't work, you could build a custom control that is basically a sap.m.Dialog with 2 sap.m.Lists on top of each other to replicate what you are describing. The top displaying selected items then the bottom, the standard list.
If we look at how other UIs manage multi-select, it is actually 2 lists side-by-side. Selecting/deselecting is simply moving the item from one side to the other (buttons in between or drag and drop). That way you always keep the context of the selected while looking for another to select. I've implemented this recently myself for choosing multiple options from a long list.
Alternatively, don't bother with multi-select on the dialog but simply keep the selected state in a sap.m.MultiInput as sap.m.Tokens. This is probably least work of all.
You can try to set rememberSelections = true, to store the current selection and load this state when the dialog is opened again.
<SelectDialog
id="idSel"
rememberSelections="true"
growingThreshold="50"
growing="true"
showClearButton="true"
items="{data>AllItems}"
multiSelect="true"
noDataText="Not Found"
liveChange="handleSearch"
title="Choose"
autoAdjustWidth="true"
growingScrollToLoad="true">
<StandardListItem id="idItem" description="{data>AllDataId})"
title="{data>Title}" type="Active"/>
</SelectDialog>

dgrid ColumnHider: disabling the hide columns menu?

I have a dgrid with a permanently hidden column that needs to be there, because I need to filter the table on its values. I am using ColumnHider in order to hide it and it works fine.
However, using ColumnHider also shows the small "+" button in the table corner that is used to hide/show columns, and I really don't want that button to show (hiding/showing columns is not a functionality we need to offer). I know I can use the unhideable property on the column, but this simply removes them from the menu. Even if I set all columns as unhideable, the button is still there with an empty menu.
Apart from hiding it with CSS, which I did, is there a way to tell ColumnHider not to show that menu at all?
Thanks, regards.
There's no programmatic way to completely hide the ColumnHider menu. The simplest way is with CSS, e.g.:
.dgrid .dgrid-column-hider-toggle {
display: none;
}
It's also possible to just suppress a column from ColumnHider's list by adding unhidable: true to the column's definition.
However, it's not fully clear to me whether you even need the ColumnHider extension. Regardless of what's in your actual data, if you don't want a particular field to be displayed in the grid, just don't define a column for it in columns (or whichever property you're using, e.g. subRows or columnSets). You'll still have the full data item available to you e.g. for renderCell functions and if you extend renderRow.

Angular ng- grid - hide/remove column input from column menu

When you use the flag 'showColumnMenu' with true value.
the ng-grid is rendered with button on the right end top panel.
Using this button we can hide/show the column on the grid.
In my Case I don't want to make it possible for some column to be visible on the grid - Meaning I want the the column menu box will be rendered with out some column.
Iv'e created plunker which demonstrated my problem
> http://plnkr.co/edit/VXOzBIRfyY3FoCTct9PI?p=preview
In that plnkr - I set column 'Id' to be invisible using (visible: false)
But if the user click on the column menu on the right end panel
he will be able to set it visible..
EDIT
Another scenario that I need to cover is case where there is some other
column say 'name' that I don't want the let the user configure it (by setting it as invisible) inside the column menu - meaning that column 'name' must always be on the grid!
and the user does not need to see it in the column menu..
So, if only i could hide those columns (id,name) inside the column menu
my problem will be solved..
Thanks!
You can do that editing a bit menuTemplate.html in ng-grid source file
Find line starting from :$templateCache.put('menuTemplate.html',
and line
<label><input ng-disabled=\"col.pinned\" type=\"checkbox\" class=\"ngColListCheckbox\" ng-model=\"col.visible\"/>{{col.displayName}}</label>\r" +
change to
<label ng-hide=\"col.colDef.alwaysVisible\"><input ng-disabled=\"col.pinned\" type=\"checkbox\" class=\"ngColListCheckbox\" ng-model=\"col.visible\"/>{{col.displayName}}</label>\r" +
now you can add
alwaysVisible:true
to columnDefs and it's done
Please see here working demo http://plnkr.co/edit/qmoILJ5LTMSlH7Uv9Rw8?p=preview
Why not just turn off the column menu? It sounds like you basically don't want to use it anyway. Is it important for your users to be able to hide the age column, when they can't control any other?
For hiding ID, I'd recommend not putting in the list of columns in the first place. Even if you don't include it in the grid, it will still be present in the data and accessible by your code. The grid is just a place to display information to the user, so don't put info in there that you don't want to display.
Edit: Check out UI-Grid, the updated version of the Ng-Grid project: http://ui-grid.info/
It has a new ColumnDef property, "EnableHiding" for exactly this case.
Here's their documentation for upgrading from ng-grid: http://ui-grid.info/docs/#/tutorial/099_upgrading_from_2

Qooxdoo - celleditor problem with selectbox

I've made table with celleditor similar to this:
http://demo.qooxdoo.org/current/demobrowser/#table~Table_Cell_Editor.html
-row 'Status' with selectbox (I need to remember in this selectbox for items - name and ID).
But problem is like in this example - when I select an option and deactivate this editor (edit other row, or click somewhere else), and then return to edit it again, then it is selected other option than it was before - always first element on list.
I think it's a bug in qooxdoo (version 1.4.1), but do you have any solution for this (too keep correct element selected when I edit this cell again?
I believe the standard solution to this problem is to keep a 'presentation model' of the user interface state. When the widget is shown again, you reconfigure it with the selection box showing the last used item or whatever you consider appropriate.

Clicking contained element also effectively (but wrongly) clicks its container

This is the problem page I'm developing.
Consider the leftmost column header, with header text "Undr." Here is the simplified html for that column header:
<th class="underlying" onclick="toggleColSelect(this);">
<img class='ad' onclick="toggleColSortOrder(this);">
Undr
</th>
The user can do two things in the column header:
select and deselect the column, by clicking the column header. EDIT: The column is selected when the column header has a yellow background; and unselected when the column header has a white background.
select ascending or descending sort on the column contents, by clicking the up/down-arrow image.
However, clicking the image also selects/deselects the column, which I don't want. When he clicks the image, I want to toggle the sort order only; I don't want to toggle the select on the column.
My JavaScript function toggleColSortOrder(); does indeed toggle only the sort order; but it seems the function to select the column also gets called (wrongly) when the user clicks the image.
What I've tried: thinking this might somehow be a manifestation of bubble-up at work, I tried all combinations of returning true, false and nothing in each of the two functions. None of this had any effect. I'd like to avoid hacking the JavaScript any further.
Question: how, by changing my html or css, can I prevent the function toggleColSelect(); being called when the user clicks inside the up/down-arrow image?
Your can cancel event-bubbling by adding
event.cancelBubble = true;
to your functions. See this fiddle: http://jsfiddle.net/fcyCz/
Here is my theory, since your <img> tag is INSIDE your <th> tag, you cannot click the <img> without first 'clicking' through the <th>. If there was a way to un-nest these two tags, I would then assume that their functions would be called separately. Possibly using a <div> to align your <img> over the correct spot. I am going to try to do live adjusting of what I just said using firebug and see (if it doesnt break the javascript) if it works, and I will report back.
Good luck.
As Tomalak points out, the click event for the <img> is bubbling up to the parent <th>, and so you must specify otherwise in your function. Also, add a call to event.stopPropagation() for the browsers which have deprecated cancelBubble.

Categories

Resources