How to filter flex datagrid with three check boxes.? - flex3

I am new to flex.
I need your help. Can anyone help me please.
My Requirement:
Flex Datagrid should be filter based on 3 checkboxes.(Checkboxes can be checked with several combinations).
My Code:
Checkboxes:
Data Provider:
MXML code:
Here i have to filter the datagrid when i check the different combinations of 3 checkboxes.
The checkbox values are from Staus column of arraycollection.
When i select 'completed' checkbox and 'onhold' check box, datagrid should display only those records which have Status as "Completed" & "On Hold".
Similarly for all combinations of c
Can anyone give simple solution please ?
Thanks,
Anand.k

Use an ArrayCollection as your dataProvider and assign a filtering function to its filterFunction property :
var provider:ArrayCollection;
At the part where you instantiate your array, give it a filterFunction :
provider.filterFunction = myFilteringFunction;
With the code of the filterFunction like this :
private function myFilteringFunction(item:ObjectTypeInYourArray) : Boolean {
var show:Boolean;
if(item.completed == checkBox1.checked &&
item.onHold == checkBox2.checked){
show = true;
}
return show;
}
It's an example with two checkboxes. The type of value assigned to the completed and onHold attributes of your object may not be boolean so you'll have to convert them somehow before comparing them to the state of the checkboxes but I think you get the idea.
Basically the filterFunction that you pass to your arraycollection is applied to each of the items inside and return true or false depending on you code inside (e.g check if the object has the right values for its properties). When true the values are showed
At the change events of your checkboxes, you refresh the dataProvider :
provider.refresh();
Hope that helps

Related

Set input value that has been binded with v-model

I'm creating my own autocomplete feature based on vue.js and materializecss.
https://jsfiddle.net/guanzo/kykubquh/5/
Right now it's working okay, except for a few things.
The normal behavior for an autocomplete is that once you select an item by pressing enter, or clicking, the value of the input becomes your selected item. So if you input "alab", and select the item "Alabama", the value of the input should become "Alabama", and the dropdown list disappears.
The problem is that the input is bound with v-model="query", meaning the value of the input is the value of "query", which is the value of the input.
Trying to change the input value with this.$el.querySelector('input').value = "Alabama" does nothing. My current workaround is to set the value of query to be the value of the selected state.
onSelect(state){
this.selected = state;
this.query = state.name//replace input val
}
A nasty side effect of this is that changing the value of query triggers another search, which causes the dropdown to reappear with the item "Alabama".
How do i change the value of an input that has been bound with v-model?
My attempted workaround is to call this.onBlurInput(); after the user selects an item, which hides the dropdown. However, the dropdown will no longer appear until you explicity refocus the input by clicking outside and back again.
Remove your focus and blur events and add the following line to your queryMatches. You really only want to show options when there is not an exact match.
queryMatches(){
if(this.query.length <= 1){
return [];
}
// check to see if the current value is already in the list
if (this.query === this.selected.name) return [];
console.log(this.query)
var reg = new RegExp(this.query,'gi')
var matches = this.states.filter(state=>{
return reg.test(state.name)
})
console.log(matches)
return matches
}
Here is an updated fiddle.

How to clear Kendo grid rows without invoking databound method?

I have a grid with databound method which shows the message 'No Data Found for the search' in case no data gets retrieved after performing search. Now i have added a radio buttons which when clicked needs to clear the old data from the grid. The issue is i am using the code $(grid).data("kendoGrid").dataSource.data([]); which does clear the grid but it also shows 'No Data Found for the search' message. Since user didn't perform any search but only changed the radio button it doesn't seem right to display that message in the grid. So, i was wondering if there was a way to clear the grid without invoking the databound method.
Grid code that calls databound function:
#(Html.Kendo().Grid<SearchModel>()
.Events(events => events.DataBound("gridDataBound"))
Databound code:
function gridDataBound(e) {
var grid = e.sender;
var gridName = "#" + grid.table.context.id;
if (grid.dataSource.total() == 0) {
var colCount = grid.columns.length;
$(e.sender.wrapper)
.find('tbody')
.append('<tr class="kendo-data-row"><td colspan="' + colCount + '" class="no-data">No Records Meet Your Search Criteria.</td></tr>');
}
$(gridName).find(".k-pager-wrap").hide();
};
Thanks.
As far as i know there is no way of doing this without putting an e.preventDefault() in the dataBound function. What you can do is maybe make a boolean that your dataBound function uses to check whether it should display the message or not?

Datatables: Showing a summary row for sub rows

I'm new to Datatables...
I'm making a grid of rows, each with sub (details) rows. I'm using server-side data from a mysql database. It is returned as JSON containing all sub rows.
I need to create the "main" grid rows, summing up columns from the sub rows. I'm not sure if Datatables can do this or how it is done...
I'm thinking about starting by getting the JSON in a JQuery function. Then using a loop to sum up data I need and pass that on to the grid as array-data. Lastly I render the grid.
Is this best practice or is Datatables capable of doing it in a smarter way?
-- the concept of sub rows can be seen here: http://datatables.net/blog/Drill-down_rows --
I have completed something like this. I returned all the data I needed and put the "details" information into the last column in a hidden div. Then used a row click to put that information into the details row.
//In the example the table the first column has a plus icon that gets replace with a minus icon
// the last column added a hidden div that contained the details.
$("#results").dataTable({
"fnCreatedRow": function (nRow, aData, iDataIndex) {
//Attach the on click event to the row
var oTable = this;
$("td:eq(0) span", nRow).on("click", function () {
//First column has a image with the jQuery UI plus icon
if ($(this).hasClass("ui-icon-circle-plus")) {
//The details information is stored in the last column in a hidden div with the class wrapper
//Grab the hidden information and append that to the new row.
oTable.fnOpen(nRow, $(".wraper", nRow).html(), "details");
} else {
oTable.fnClose(nRow);
}
$(this).toggleClass("ui-icon-circle-plus ui-icon-circle-minus");
});
}
});

Dojo EnhancedGrid and programmatic selection

Here's my problem: in my application I have a Dojo EnhancedGrid, backed up by an ItemFileReadStore. The page flow looks like this:
The user selects a value from a selection list.
The item from the list is posted on a server and then the grid is updated with data from the server (don't ask why, this is how it's supposed to work)
The new item is highlighted in the grid.
Now, the first two steps work like a charm; however, the third step gave me some headaches. After the data is successfully POSTed to the server (via dojo.xhrPost() ) the following code runs:
myGrid.store.close();
myGrid._refresh();
myGrid.store.fetch({
onComplete : function(items) {
for ( var i = 0; i < items.length; i++) {
if (items[i].documentType[0].id == documentTypeId) {
var newItemIndex = myGrid.getItemIndex(items[i]);
exportMappingGrid.selection.deselectAll();
exportMappingGrid.selection.addToSelection(newItemIndex);
}
}
}
});
Now, the selection of the grid is updated (i.e. the selection object has a selectedIndex > 0), but visually there's no response, unless I hover the mouse over the "selected" row. If I remove the .deselectAll() line (which I suspected as the culprit) then I sometimes end up with two items selected at once, although the grid selectionMode attribute is set to single.
Any thoughts on this one?
Thanks a lot.
You need to use setSelected(), like so
exportMappingGrid.selection.setSelected(newItemIndex, true);
The second parameter is true to select the row, false to unselect it.
This is what works for me:
grid.selection.clear();
grid.selection.addToSelection(newItemIndex);
grid.selection.getFirstSelected();
Jon

On demand color set of rows in SmartClient (TreeGrid)

I have a TreeGrid in SmartClient. Now I want to color some set of lines like line numbers 3-5, 7-11 etc. I am using an external button which passes the values to the SmartClient. Can anybody tell me how to do that? A button is passing the value and it's working fine. But the problem is, where to get the value in SmartClient and how can I color that set of lines.
Since TreeGrid is a ListGrid, I would imagine you could override the getCellStyle function and set the colors as you see necessary.
http://www.smartclient.com/docs/8.1/a/b/c/go.html#search=getcellstyle
So basically in pseudo code:
if (row >= 3 and row <=5)
return "style1"
if (row >= 7 and row <=11)
return "style2"
else
return this.baseStyle
where style1 and 2 are defined in css
And how to custom and keep states with using specific style name (myStyle) like :
myStyle
myStyleDark
myStyleOver
myStyleOverDark
myStyleSelected
myStyleSelectedDark
myStyleSelectedOver
myStyleSelectedOverDark
myStyleDisabled
myStyleDisabledDark
I try to use #Override of getCellStyle
for returning "myStyleA" or "myStyleB"
which i want conserve dynamics suffixs : "Dark", "Over", "Selected", ...
An idea ?...
http://www.smartclient.com/smartgwt/javadoc/com/smartgwt/client/widgets/grid/ListGrid.html
The state of the record is indicated by adding a suffix to the base style.
There are four independent boolean states, which are combined in the order given:
"Disabled" : whether the cell is disabled; enable by setting the "enabled" flag on record returned by getCellRecord
"Selected" : whether cell is selected; enable by passing a Selection object as "selection"
"Over" : mouse is over this cell; enable with showRollovers
"Dark" : alternating color bands; enable with alternateRowStyles