Kendo Hierarchical Datasource for treeview, filter to checked nodes - datasource

I am using the Kendo Hierarchical Datasource for a Kendo UI Treeview.
On a click event, I want to leave only the checked roms in the datasource.
I tried
$('#treeview')
.getKendoTreeView()
.dataSource
.filter({
field: "checked",
operator: "eq",
value: true });
But to no avail.
Do I have the correct field?
Also, for bonus points, how do I remove the filter?

checked is the correct field if you have defined it as so in the template :
$("#treeview").kendoTreeView({
checkboxes: { template: "<input type='checkbox' name='checkedNodes' #= item.isChecked ? 'checked' : '' # value='#= item.id #' />" },
dataSource: [{
id: 1, text: "My Documents", expanded: true, spriteCssClass: "rootfolder", items: [
{ id: 2, text: "about.html", expanded: true, isChecked: false, spriteCssClass: "folder" },
{ id: 3, text: "index.html", expanded: true, isChecked: true, spriteCssClass: "folder" }
]
}]
});
in my case, it is named isChecked (see item.isChecked in my code).
But, in order to filter correctly, be careful : filter only acts on the current level (see for example this question).
And for your bonus question, to remove the filter, simply apply the following code :
$('#treeview')
.data("kendoTreeView")
.dataSource
.filter({ });
(same as before on all levels on your hierarchy!).
Edit
Here is some fiddle in order to play with the filter : http://jsfiddle.net/scaillerie/RHh67/ .

Related

static filter data is cleared after a search is performed - yadcf plugin

i am trying to setup a true/false filter with the yadcf plugin. As far as i can tell, it works fine and the filtering works fine, until after you have performed a search. At which point the select list is no longer rendered (Even clearing the filter doesn't bring it back) and a page refresh is needed to bring it back.
Here are some screenshots that should help demonstrate the problem.
This is before a search has been performed
This is after a search has been performed
Here is the datatable/yadcf init (I've removed some code for brevity).
_grid.init({
loadingMessage: 'Loading...',
src: _connectionsTable,
dataTable: {
ajax: {
url: _connectionsTable.data('url')
},
columns: [
{
data: 'IsAssigned',
sortable: false,
"render": function (data, type, full, meta) {
return (data === false
? '<span class="label label-sm label-danger"> No </span>'
: '<span class="label label-sm label-success"> Yes </span>');
}
}
],
dom:
"<'row'<'col-md-8 col-sm-12'pli><'col-md-4 col-sm-12'<'table-group-actions pull-right'>>r>t<'row'<'col-md-8 col-sm-12'pli><'col-md-4 col-sm-12'>>",
initComplete: function (settings, json) {
var _table = new $.fn.dataTable.Api(settings);
// search options
yadcf.init(_table, [
{
column_number: 11,
data: [{ value: 'true', label: 'Yes' }, { value: 'false', label: 'No' }],
filter_container_id: 'IsAssignedFilter',
filter_reset_button_text: false,
style_class: 'form-control form-filter input-sm'
}
]);
},
order: [
[1, 'desc']
],
responsive: true,
stateSave: true
}
});
The other types of searches seem to be working ok, but this is the first one i have provided static data for. Also Chrome dev tools doesn't show any errors when this happens.
Any help is appreciated!
You should not init yadcf in initComplete , instead do it after you init datatables, like this:
var oTable = $('#example').DataTable({...});
yadcf.init(oTable, [{column_number: 0}]);

How to get the list of selected rows in Dgrid selection mixin

I am using Selector and Selection Mixin in Dgrid ondemandgrid.I am using checkbox as a selector.Below are my questions.
How to get the List of Checked rows in a javascript on a html button click?I know there is a dgrid-select and deselect events,but i want the list of all the selected rows on a button click event.
Currently , if i click on a row at any position ,the checkbox is getting selected.But I want to select the row only when i click on the checkbox.How to achieve this?
Here is my code
require([
"dgrid/OnDemandGrid",
"dojo/store/JsonRest",
"dojo/dom",
"dojo/dom-style",
"dojo/_base/declare",
"dgrid/extensions/ColumnResizer",
"dgrid/Selection",
"dgrid/selector"
], function (OnDemandGrid,JsonRest,dom,domStyle,declare,ColumnResizer,Selection, selector) {
var Layout = [
selector({ label: selector({}), selectorType: "checkbox" }),
{field: 'srno',label: 'Sr No'},
{field: "Name",label: "name"}
];
jsonstore = new JsonRest({target: url,idProperty: "srno"});
grid = new(declare([OnDemandGrid,ColumnResizer,Selection]))({
store: jsonstore,
columns: Layout,
minRowsPerPage : 40,
maxRowsPerPage : 40,
keepScrollPosition : true,
allowSelectAll: true,
loadingMessage: "Loading data...",
noDataMessage: "No results found."
}, "grid");
domStyle.set(dom.byId("grid"),"height","210px");
grid.startup();
grid.on("dgrid-select", function(event){
//
});
grid.on("dgrid-deselect", function(event){
//
});
});
Here is the solution of your questions:
var Layout = [
selector({ label: '', sortable: false}),
{field: 'srno',label: 'Sr No'},
{field: "Name",label: "name"}
];
jsonstore = new JsonRest({target: url,idProperty: "srno"});
grid = new(declare([OnDemandGrid,ColumnResizer,Selection]))({
store: jsonstore,
columns: Layout,
minRowsPerPage : 40,
maxRowsPerPage : 40,
selectionMode: "none",
deselectOnRefresh: false,
keepScrollPosition : true,
allowSelectAll: true,
loadingMessage: "Loading data...",
noDataMessage: "No results found."
}, "grid");
new Button({
label: "Ok",
onClick: function () {
// here you can use grid.selection to get the list of selected rows.
// it is an object with { 'rowid': true} format for example, like below
array.forEach(grid.store.data, function (item) {
if (grid.selection[item.id]) {
//your code to handle this selected item
}
});
})
}, 'button');
For 1: declare a var selection = [];
then,
grid.on("dgrid-select", function(event){
var selected = grid.selection;
if (selected) {
for (row in selected) {
selection.push(row);
}
}
});
and splice it on dgrid-deselect
then access the array on button click.
For 2: define the grid with selectionMode: "none",
From the docs: https://github.com/SitePen/dgrid/wiki/Selection
this.grid.on(".dgrid-row:dblclick", function(vet) {
// your selected row
var row = self.grid.row(vet);
});
you can get selected rows in this handler .
the selectedRows variable give you any selected items in grid
window.grid = new (declare([Grid, ColumnResizer, Selection]))({
store: jsonstore,
columns: Layout,
minRowsPerPage: 40,
maxRowsPerPage: 40,
keepScrollPosition: true,
allowSelectAll: true,
loadingMessage: "Loading data...",
noDataMessage: "No results found."
}, "grid");
window.grid.on("dgrid-select", function (event) {
var selectedRows = event.rows;
});

Paging and grouping in dynamic grid

I am using dynamic grid using this plugin.
I want to make paging in it,
I tried like,
Ext.define('....', {
extend: 'Ext.data.Store',
pageSize: 10,
proxy: {
type: 'rest',
url: me.url,
reader: {
type: 'dynamicReader',
totalProperty: 'totalCount'
}
}
});
me.bbar = Ext.create('Ext.PagingToolbar', {
store: me.store,
displayInfo: true,
displayMsg: 'Displaying topics {0} - {1} of {2}',
emptyMsg: "No topics to display"
});
In DynamicGrid.js totalProperty is not working. Am I setting the property properly there?
Then I am also trying to make grouping in the same plugin.
I have a combobox with some fields and want to select grouping field from it dynamically. When I select a field in combo box, it sends that data to grid's groupField property.
I have that combo box value selected in controller like,
var groupData = Ext.ComponentQuery.query('#groupid')[0].getValue();
I am sending it to grid like,
Ext.define('Group', {
singleton: true,
param: groupData
});
I am getting that for grid property (in DynamicGrid.js) like,
groupField: [Group.param]
But this automatically selects first field for groupField property before even selecting anything in combo box and makes grouping, selecting other fields in combo box also doesn't work, it always has first field for grouping.
What is going wrong? Please help.
I did grouping successfully by adding the following code in listener,
me.store.group(Group.param);
Still having issues with totalProperty, can someone help me to make it work?
I think I am making a mistake, now actual JSON response is,
[{
"userId": 123,
"name": "Ed Spencer",
"email": "ed#sencha.com"
}]
So the code for getting data and manipulating works fine like,
readRecords: function(data) {
if (data.length > 0) {
var item = data[0];
var fields = new Array();
var columns = new Array();
var p;
for (p in item) {
if (p && p != undefined) {
fields.push({name: p, type: 'floatOrString'});
columns.push({text: p, dataIndex: p});
}
}
data.metaData = { fields: fields, columns: columns };
}
return this.callParent([data]);
}
But for sending other metaData properties, from the docs I should probably have the following JSON response,
{
"count": 1,
"ok": true,
"msg": "Users found",
"users": [{
"userId": 123,
"name": "Ed Spencer",
"email": "ed#sencha.com"
}],
"metaData": {
"root": "users",
"idProperty": 'userId',
"totalProperty": 'count',
"successProperty": 'ok',
"messageProperty": 'msg'
}
}
So how do I point root in the readReords function so that it knows data is in root?
Thereby I will have other metaData properties also passed.
Please help!

Extjs combo box always showing the first element selected

I am new to Extjs. I am facing this problem when I am trying to use combobox with a store that is populated through an AJAX call. I want the combobox to display the item that starts with the character typed in the combo box but the combobox is always showing the 1st item in the list.Here is my code,
Ext.define('fieldModel', {
extend : 'Ext.data.Model',
fields : [ {
name : 'name'
},{
name : 'value'
}]
});
{
xtype: 'combobox',
id: 'startField',
name: 'startField',
style: 'margin-right:10px;',
width: 230,
fieldLabel: 'Field',
labelAlign: 'top',
displayField: 'name',
valueField: 'value',
triggerAction:'query',
minChars:2,
//forceSelection:true,
//enableKeyEvents:true,
minListWidth:150,
//allowBlank:false,
queryMode: 'remote',
typeAhead: true,
//hideTrigger: true,
store:new Ext.data.JsonStore({
model: 'fieldModel',
//autoLoad: true,
//sortOnLoad : true,
//sortRoot: 'data',
proxy : {
type : 'ajax',
url: requesturl + '?action=getDate&itemid='+ preItemId,
reader : {
type : 'json',
root : 'data',
}
},
listeners :{
load : function( store, records, successful, operation, eOpts){
Ext.getCmp('startField').getStore().sort('name', 'ASC');
}
}
}),
Please help.
Thanks in advance.
change your listener to keypress or keyup event
keypress( Ext.form.field.Text this, Ext.EventObject e, Object eOpts )
This event only fires if enableKeyEvents is set to true.
listeners :{
keypress : function( text, event, eOpts){
Ext.getCmp('startField').getStore().sort('name', 'ASC');
}
}

ExtJs:Search Filter in combo box

I have a combo box with list a set of values,
Ext.define('loincList', {
extend: 'Ext.data.Model',
fields: [{ name: 'loincNumber', mapping: 'loincNumber' },
{ name: 'component', mapping: 'component' }
]
});
ds = Ext.create('Ext.data.Store', {
model: 'loincList',
proxy: {
type: 'ajax',
url : url+'/lochweb/loch/LOINCData/getLOINCData',
reader: {
type: 'json',
root: 'LOINCData'
}
}
});
combo box:
{
xtype: 'combo',
fieldLabel: 'Search Loinc Code',
name: "loincId",
displayField: 'loincNumber',
valueField: 'id',
width: 400,
store: ds,
queryMode: 'local',
allowBlank:false,
listConfig: {
getInnerTpl: function() {
return '<div data-qtip="{loincNumber}.{component}">{loincNumber} {component} {status}</div>';
}
}
}
when i type a number in the combo-box it filter based on the number entered but when i type a text ,it is not filtering based on text entered.How to filter based on text entered.
When you type the data to the combobox, it will filter based on the displayField. So I think when you "type a text it is not filtering based on text entered" because no items in the combo has displayField with prefix like the text you typed.
Filtering is working on server side, if you will switch on something like Firebug, you will see special param (usually named filter) with text you typed in control, So you need to check what happen on your server-side. You need to handle with filter text and make filters as you want on server-side.