I have a columntoggle table with some information in it.
I would like to get what are the selected columns, to stock those values in a database and when the user logs back in, using those values to make the table load with the columns he has previously selected.
Is there any way to do this?
Thanks by advance
There is nothing built-in to do this. Here is one way to do it:
jQM creates a column toggle popup with a checkbox for each column assigned a data-priority. The popup takes the id of the table plus '-popup', so you can access the checkboxes with this selector:
$("#myTableid-popup .ui-checkbox label");
Checked items have the class .ui-checkbox-on, while unchecked items have .ui-checkbox-off. Therefore you could get the indexes (indices) of all visible columns:
var selIndex = [];
function SaveSelectedColumns(){
selIndex = [];
$("#myTable-popup .ui-checkbox label").each(function(idx){
if ($(this).hasClass("ui-checkbox-on")){
selIndex.push(idx);
}
});
}
Then to restore visible columns:
function LoadSavedColumns(){
$("#myTable-popup .ui-checkbox label").each(function(idx){
var vis = IsColVisible(idx);
if ($(this).hasClass("ui-checkbox-on") && !vis){
$(this).click();
}
if ($(this).hasClass("ui-checkbox-off") && vis){
$(this).click();
}
});
}
function IsColVisible(idx){
for (var i=0; i<selIndex.length; i++){
if (selIndex[i] == idx) return true;
}
return false;
}
Working DEMO
Related
I want to set active tab in jquery ui tabs based on output of a function active_tab(), but active_tab() function do not run when tabs are initialized.
function active_tab()
{
var t = 1;
// some conditions
return t;
}
$( "#tabs1" ).tabs({
active: function(){
active_tab();
}
});
jQuery UI Tabs option for active expects a number, true, or false.
Which panel is currently open. Multiple types supported:
Boolean: Setting active to false will collapse all panels. This requires the collapsible option to be true.
Integer: The zero-based index of the panel that is active (open). A negative value selects panels going backward from the last panel.
I would advise the following type of code:
function active_tab(tbs, i){
if(i == undefined){
i = 0;
}
// Add Other Conditions
tbs.tabs("option", "activate", i);
return i;
}
$("#tabs1").tabs();
activate_tabs($("#tabs1"), 1);
Another method would be:
function active_tab(){
var t = 1;
// some conditions
return t;
}
$("#tabs1").tabs();
$("#tabs1").tabs("option", "activate", activate_tab());
You can also do the following:
$("#tabs1").tabs({
activate: activate_tab()
});
I have a store filled on application init.
It is used in multiselect combobox in a view where I select records that I want and add their id's to a variable.
In grid I have a combobox with the same store, and I want to filter out store so it only contains the id's I have selected.
setViewData : function(dataStore, record, readOnly) {
var store = Ext.getStore('ScaleStore');
store.clearFilter();
store.filterBy(function (scaleRecord) {
Ext.each(record.data.scaleList, function (scale) {
if(scale.id == scaleRecord.data.schl1NrId) {
return true;
}
});
});
}
The store contains 5 records.
record.data.scaleList - here I have lets say 3 records out of 5 I have selected in the multiselect combobox.
My goal is to have only the ones I have selected(3 out of 5) displayed in the grid combobox.
With this code I get all of the records, or wrong ones at random.
Any pointers to what I am doing wrong here?
Thank you all :)
It seems you are using Ext.each incorrectly. The documentation on Ext.each states the following:
The iteration can be stopped by returning false from the callback
function. Returning undefined (i.e return;) will only exit the
callback function and proceed with the next iteration of the loop.
Which means you are not returning the values that you want to filter. To do so, and assuming that you still want to use Ext.each, you would have to do the following:
store.filterBy(function (scaleRecord) { // This function is executed
// for each record
var filter = false;
Ext.each(record.data.scaleList, function (scale) {
if(scale.id == scaleRecord.data.schl1NrId) {
filter = true;
return false; // return false if you want to stop the iteration
}
});
return filter; // return the boolean to apply the
// filter to the current record
});
I have two array called 1.Courses and 2.Categories each courses have different category i want to filter the courses by category using mat-checkbox.
example: javascript is a course name and scripting is category .
Here is the stackblitz link
and below is the screen shot of the approach:
It should work on multiple checkbox filtering Thank you in advance.
So, the simplest way to do this with your current approach, IMO, would be to create a new course array filteredCourses and iterate that in your template.
OnInit, set filteredCourses to courses so it renders them all on init.
ngOnInit() {
this.filteredCourses = this.courses;
}
Next, you need some way of maintaining a list of the selected categories. This would be much easier if you used Angulars built in forms, but, in the absence of that, may I suggest the following:
onSelect (click), add the clicked category to a list of selected categories (on click, if it's not there, add it, else, remove it)
onSelect(selectedCategory: any) {
this.selectCategory(selectedCategory);
}
selectCategory(selectedCategory: any) {
const index: number = this.selectedCategories.findIndex((cat: any) => {
return cat.id === selectedCategory.id
});
if ( index === -1) {
this.selectedCategories.push(selectedCategory);
} else {
this.selectedCategories.splice(index, 1);
}
}
The next step would then to be to filter your courses array to only those where the the categoryId is included in the list of selectedCategories and set your filteredCourses array with the result, allowing the template to update. So, your onSelect function becomes:
onSelect(selectedCategory: any) {
this.selectCategory(selectedCategory);
this.filteredCourses = this.courses.filter((course: any) => {
return this.selectedCategories.findIndex((cat: any) => {
return course.categoryId === cat.id;
}) !== -1;
});
}
Updated blitz with suggestion: https://stackblitz.com/edit/mat-checkbox-kq6xgd
I have a TFDTable the is connected to a TGrid using LiveBindings and the data displays sorted by the indexes in the table itself. I want to be able to change the sort order by clicking on the header of the grid. Here is what I have done so far:
void __fastcall TmainFrm::Grid7HeaderClick(TColumn *Column)
{
if(IBS_EntityTable->IndexName == Column->Header)
return; // if it is being sorted by the same column, don't do anything
try
{
TFDIndex* pIndex;
IBS_EntityTable->Indexes->BeginUpdate();
IBS_EntityTable->Indexes->Clear();
pIndex = IBS_EntityTable->Indexes->Add();
pIndex->Name = Column->Header;
pIndex->Fields = Column->Header;
pIndex->Active = true;
IBS_EntityTable->IndexName = pIndex->Name;
}
__finally
{
IBS_EntityTable->Indexes->EndUpdate();
IBS_EntityTable->Refresh();
}
}
but the sort order does not change. In fact the only data that does change is the selected row. What am I doing wrong?
Thank youSam
I have created a select interaction for my ol3 map and attached a select event handler.
selectInteraction = new ol.interaction.Select({
...
});
selectInteraction.on('select', function (evt) {
???;
});
How do I interrogate 'evt' to determine:
Which feature was clicked to fire the event?
The ID and other attributes of this feature?
Whether the feature was selected or deselected?
The select event emitted by the ol.SelectInteraction is documented here.
As you can see, evt.selected will be an array of all features that were just selected. It will not contain already selected features which are kept selected when clicking a new feature while the addCondition is true. These are the clicked features that were not already selected and matched the filters to be included in the selection.
Likewise, evt.deselected will contain any features that were just deselected.
You can get the ID and properties of each feature with:
var featureID = feature.getId()
var properties = feature.getProperties()
var someSpecificProperty = feature.get("property-name")
See the docs for ol.Feature for more info on the feature and it's attributes.
Here are some items that should help you.. evt.selected gets you the features that are selected. This example is on a clustered layer and you can use the get function on features selected to retrieve properties from the object selected. If you don't know properties available to you then use console.dir(evt) to examine the object using the console.
selectInteraction.on('select', function(evt){
var coord = evt.mapBrowserEvent.coordinate;
var selItems = evt.selected;
var sellength = selItems.length;
var rptFrame = parent.window.frames["rptframe"];
for (var i = 0; i < sellength; i++) {
var label = selItems[i].get('l');
var url = selItems[i].get('url');
if (url) {
rptFrame.location.href = url;
} else {
var feaObj = selItems[i].get('features');
if (feaObj.length == 1) {
url = feaObj[0].get('url');
rptFrame.location.href = url;
} else {
writeMultiSelect(rptFrame,selItems);
}
}
}
});