Tabulator setHeaderFilter before inital AJAX call? - tabulator

I am trying to set a default headerFilter value before the table loads. I tried all the way up to tableBuild callback. Still getting 2 calls to the API, one for the regular non-filtered data then one with the default filter. The column initialValue and defaultValue params do not seem to affect filterHeaders which is why I am going down this rabbit hole.
tableBuilt: function () {
console.log("tableBuilt");
this.setHeaderFilterValue("status", "Inactive");
}

Try the initialHeaderFilter value during table creation.
initialHeaderFilter: [{field: 'fieldName', value: 'filter value'}]
http://tabulator.info/docs/4.6/filter#header
Here is a working example.
https://jsfiddle.net/nrayburn/r319zaep/40/

Related

Update bottomCalc-value, based on selection (if any)

I just found Tabulator, and i love it. I'm currently using version 4.5. The bottomCalc-function isuseful, however, i would like it to be updated, based on the selection of row(s).
Is there a native option i've missed, or, should it be done manually, fx. triggered by the row-selections?
Column example:
{
title: 'Offline Amount',
field: 'offline',
bottomCalc: 'sum',
formatter: 'html',
align: 'center',
width: 150,
},
And selectField: true for columns.
Currenly, without updated bottomCalc:
And, i would like it to be updated, based on the selection (if there is any).
Update:
I guess the rowSelectionChanged-option, will be the best way to handle the update of .tabulator-footer .tabulator-calcs-holder, but i'm still unsure about, how to do that part.
If it's a question of looping through the selected values, calculate the sum, and update the value - or if i'm able to use another event, reuse a specific function, or yet another thing.
There is no built in way to achieve this but there may be a work around.
You could store a property in the row data that stores the selected state of the row. You could then use the rowSelected and rowDeselected callbacks to change this value.
You could then use a Custom Calculation Function to then generate the sum of the column values for the rows where the data object has a selected property of true.
Update
As of version 4.6, there is now a recalc function you can call on the table, so you could set up your calc function as outlined in the answer above and then use the rowSelectionChanged callback to trigger the update:
var table = new Tabulator("#example-table", {
rowSelectionChanged:function(data, rows){
table.recalc();
},
});

How do you set the value of 'DocumentShowInSiteMap' property in Kentico?

How do you set the value of DocumentShowInSiteMap property in Kentico?
I've tried:
Using the DocumentHelper and TreeHelper apis but with both, this property doesn't give you access to the setter.
Tried running a SQL Query setting the value of dbo.CMS_Document.DocumentShowInSiteMap to 1 and 0. These queries run fine but when I go to the pages app, there is no change in the 'Show in sitemap' property checkbox, ie. setting the database field to 0 doesn't 'untick' this checkbox.
I'm trying to run a scheduled task which will set this property for documents at a specified location automatically. What is the proper way to do this? Any help appreciated.
Have you tried this?
int TheDocumentToModify = 1221;
var PageItem = DocumentHelper.GetDocument(TheDocumentToModify , new TreeProvider());
foreach(var culturePage in PageItem.CultureVersions)
{
culturePage.SetValue("DocumentShowInSiteMap", true);
// May need to apply Workflow check in / check out, see Kentico API examples based on your need.
culturePage.Update();
}
Within code, there is no simple way. Setter should be available within special class DocumentCultureDataInfo and it should be saved with SetObject. This class contains all of culture DB fields and is manipulated by DocumentCultureDataInfoProvider.
This class is an internal property of TreeNode. However I have not tried doing this arbitrary in code and mentioned classes are part of innner API.
Your second approach should work, but documents and their properties are cached and you will need to refresh cache so that new DB value is actually picked up Loading of this property goes through simple GetData in LoadDefaultValues for each TreeNode.
Trevor J Fayas's answer would probably work. I figured this out yesterday and just leaving my solution here just in case:
TreeHelper
.GetDocuments(task.CurrentSiteName, aliaspath, null, false, "", "", "", -1, false, -1)
.Where(doc => doc.DocumentShowInSiteMap)
.ToList()
.ForEach(node =>
{
node.SetValue("DocumentShowInSiteMap", false);
node.Update();
});
Obviously replace aliaspath with the one you need or use DocumentHelper.GetDocuments which takes different parameters.

jqGrid filtertoolbar not firing after grid resizing

I have fixed row numbers to 10 for my subgrids, but if reccount is less than 10 I would want to adjust height subgrid to "auto" or "100%".
So here is my code for this subgrid :
// SUBGRID FOURTH LEVEL
var subgrid_table_id = subgrid_id+"_d",
pager_id = "p_"+subgrid_table_id;
$("#"+subgrid_id).append("<table id='"+subgrid_table_id+"' class='scroll'></table><div id='"+pager_id+"' class='scroll'></div>");
$("#"+subgrid_table_id).jqGrid({
url:"sg31b.php?id="+row_id+"&clt="+clt,
datatype: "json",
idPrefix:"sgd_",
colNames: ['Id','Article','Désignation','Marque','Equivalence'],
colModel: [
{name:'e.id',index:'e.id',hidden:true},
{name:'a.code',index:'a.code', width:100},
{name:'a.descr',index:'a.descr', width:450},
{name:'k.code',index:'k.code', width:80},
{name:'e.equiv',index:'e.equiv',width:100}
],
pager: pager_id,
sortname: 'a.code',
hiddengrid:true,
scroll:true,
height:230,
rowNum:10,
autowidth:true,
caption:'4 - EQUIVALENCE ARTICLES',
gridComplete:function(){
sortDataCol(this);
if($("#"+subgrid_id+"_d").jqGrid('getGridParam','records') < $("#"+subgrid_id+"_d").jqGrid('getGridParam','rowNum')){
$("#"+subgrid_id+"_d").jqGrid('setGridHeight','100%');
}else{
$("#"+subgrid_id+"_d").jqGrid('setGridParam',[{npage:1}]).jqGrid('setGridHeight',230);
}
}
});
$("#"+subgrid_table_id).jqGrid('navGrid',"#"+pager_id,{search:false,add:false,edit:false,del:false});
$("#"+subgrid_table_id).jqGrid('filterToolbar',{stringResult: true,searchOnEnter : false});
fullInputCss();
and the snapshot of result for less than 10 filtered rows :
Now if I press Backspace in search field to obtain more rows, it seems that search doesn't fire because Firebug doesn't show any trace of request :
If I delete added 'setGridHeight' lines in gridcomplete, all runs fine !
I think that one more time I'm wrong in my coding and understanding how jqGrid runs.
Please could someone give me some way to solve this trouble ?
Many thanks in advance. Have a nice day. JiheL
I suppose that the origin of the problem could be id duplicates on your page. Just now I wrote the answer on another your question where I described the problem detailed.
Current implementation of jqGrid (version 4.4.5) has problem in the code of filterToolbar which constructs id for input fields of the filter toolbar based on the following rule:
id="gs_" + cm.name
(see the line of code). It means that the id of the input field for the column a.code will be gs_a.code for every subgrid which you use. So you can have id duplicates.
So I recommend you redesign the naming concept in your code. You can use for example
name: row_id + "a_code", index: "a.code"
In the way the value like "a.code" will be still send during sorting of the grid, but you will have no id duplicates. In some scenarios (is you use repeatitems: false in jsonReader) you could need to use additional jsonmap attribute, but you don't need it in you current code.

Disable a EditorGrid row when a model attribute has been updated

Here's my request :
I have an EditorGrid which renders some rows based on its associated ListStore.
The ListStore has a collection of instances of my model which has an attribute called "markeAsDeleted" which is updated elsewhere in the UI.
My question is :
How is-it possible to change the rendering of the corresponding row to turn it 'disabled' when my 'markAsDeleted' attribute is 'true' ?
What's I'm expecting is a kind of a rendrer to add to my EditorGrid instance which updates the row as the model attribute is updated.
Thanks
Hiding the column with filtering would be your best best.
If you set store.setMonitoChanges(true); then I believe it will reconise when anything changes that model in the store and fire an storeUpdate from there you could re-Apply your filter (if it doesnt do that automatically anyway);
example
store.addStoreListener(new StoreListener<BaseModelData>() {
public void storeUpdate(StoreEvent<M> se) {
store.applyFilters("");
}
})
edit:
After reading the comments on another answer I notice you are using a Grid filter to filter the columns you could just as easily use addFilter on a store.
example
store.addFilter(new StoreFilter<BaseModelData>() {
public boolean select(Store<T> store, T parent, T item, String property) {
return !item.get("markAsDeleted");
}
});
GXT makes sure that when your Grid's store gets modified, the Grid is re-Rendered. So when other part of your application does update on the model, make sure that the same model gets updated on store EXPLICITLY.
You can use store.remove(), store.removeAll(), store.addAll() to replace the model with the updated one.

Couchdb: filter and group in a single view

I have a Couchdb database with documents of the form: { Name, Timestamp, Value }
I have a view that shows a summary grouped by name with the sum of the values. This is straight forward reduce function.
Now I want to filter the view to only take into account documents where the timestamp occured in a given range.
AFAIK this means I have to include the timestamp in the emitted key of the map function, eg. emit([doc.Timestamp, doc.Name], doc)
But as soon as I do that the reduce function no longer sees the rows grouped together to calculate the sum. If I put the name first I can group at level 1 only, but how to I filter at level 2?
Is there a way to do this?
I don't think this is possible with only one HTTP fetch and/or without additional logic in your own code.
If you emit([time, name]) you would be able to query startkey=[timeA]&endkey=[timeB]&group_level=2 to get items between timeA and timeB grouped where their timestamp and name were identical. You could then post-process this to add up whenever the names matched, but the initial result set might be larger than you want to handle.
An alternative would be to emit([name,time]). Then you could first query with group_level=1 to get a list of names [if your application doesn't already know what they'll be]. Then for each one of those you would query startkey=[nameN]&endkey=[nameN,{}]&group_level=2 to get the summary for each name.
(Note that in my query examples I've left the JSON start/end keys unencoded, so as to make them more human readable, but you'll need to apply your language's equivalent of JavaScript's encodeURIComponent on them in actual use.)
You can not make a view onto a view. You need to write another map-reduce view that has the filtering and makes the grouping in the end. Something like:
map:
function(doc) {
if (doc.timestamp > start and doc.timestamp < end ) {
emit(doc.name, doc.value);
}
}
reduce:
function(key, values, rereduce) {
return sum(values);
}
I suppose you can not store this view, and have to put it as an ad-hoc query in your application.

Resources