PDA

View Full Version : how to filter a datagrid using multiple checkbox


p0p0
02-10-2009, 02:33 AM
hye...can someone help me to filter a datagrid using multiple checkbox.for example:i have a datagrid with mutiple columns, and i want to filter those data according to;.jpeg,css,xml and so on.

how can i do this??

thnaks...

wvxvw
02-10-2009, 09:31 AM
You'd need to filter the source of the array collection you used for data provider of the data grid and then update the data grid. If you can give an example of what data do you have in the columns, an how you want it to be filtered that would help...

p0p0
02-13-2009, 09:01 AM
ok,for example,i have this code:in attachment

can u tell me how to filter the data using multiple checkbox??
when the user click one checkbox
and when the user click more than one checkbox

thank you so much

wvxvw
02-13-2009, 01:27 PM
<?xml version="1.0" encoding="utf-8"?>
<mx:Application
xmlns:mx="http://www.adobe.com/2006/mxml"
layout="vertical"
verticalAlign="top"
horizontalAlign="center"
backgroundGradientColors="[0x000000,0x323232]"
paddingTop="0"
viewSourceURL="srcview/index.html">

<mx:Script>
<![CDATA[
import flash.events.Event;
import mx.controls.CheckBox;
private var duplicateList:XMLList;

private function joanne_clickHandler(event:Event):void
{
duplicateList = null;
var cb:CheckBox = event.currentTarget as CheckBox;
var source:String = cb.selected ? cb.label : "";
if (smith.selected) source += cb.selected ? "|" +
smith.label : smith.label;
var re:RegExp = new RegExp(source);
employees.(toXMLString().match(re) ?
(duplicateList ? duplicateList += valueOf() :
duplicateList = XMLList(valueOf())) : false);
dg.dataProvider = duplicateList;
}

private function smith_clickHandler(event:Event):void
{
duplicateList = null;
var cb:CheckBox = event.currentTarget as CheckBox;
var source:String = cb.selected ? cb.label : "";
if (joanne.selected) source += cb.selected ? "|" +
joanne.label : joanne.label;
var re:RegExp = new RegExp(source);
employees.(toXMLString().match(re) ?
(duplicateList ? duplicateList += valueOf() :
duplicateList = XMLList(valueOf())) : false);
dg.dataProvider = duplicateList;
}
]]>
</mx:Script>

<mx:XMLList id="employees">
<employee>
<name>Christina Coenraets</name>
<phone>555-219-2270</phone>
<email>ccoenraets@fictitious.com</email>
<active>true</active>
<image>images/arrow_icon_sm.png</image>
</employee>
<employee>
<name>Joanne Wall</name>
<phone>555-219-2012</phone>
<email>jwall@fictitious.com</email>
<active>true</active>
</employee>
<employee>
<name>Maurice Smith</name>
<phone>555-219-2012</phone>
<email>maurice@fictitious.com</email>
<active>false</active>
</employee>
<employee>
<name>Mary Jones</name>
<phone>555-219-2000</phone>
<email>mjones@fictitious.com</email>
<active>true</active>
</employee>
</mx:XMLList>

<mx:Panel
title="DataGrid Control"
layout="vertical"
color="0xffffff"
borderAlpha="0.15"
width="500"
paddingTop="5"
paddingRight="10"
paddingBottom="10"
paddingLeft="10"
horizontalAlign="center"
height="291">

<mx:Label
width="100%"
color="0x323232"
text="Select a row in the DataGrid control."
height="49"/>

<mx:CheckBox
id="joanne"
label="Joanne"
color="#090000"
fontWeight="bold"
click="joanne_clickHandler(event)" />

<mx:CheckBox
id="smith"
label="Smith"
fontWeight="bold"
color="#040000"
click="smith_clickHandler(event)"/>

<mx:DataGrid
id="dg"
color="0x323232"
width="100%"
rowCount="3"
dataProvider="{employees}"
height="104">
<mx:columns>
<mx:DataGridColumn
dataField="name"
headerText="Name"/>
<mx:DataGridColumn
dataField="phone"
headerText="Phone"/>
<mx:DataGridColumn
dataField="email"
headerText="Email"/>
</mx:columns>
</mx:DataGrid>

</mx:Panel>
</mx:Application>
Like this maybe...

p0p0
02-17-2009, 08:36 AM
hye wxvxw...

i need your help here...

for example i want to filter a datagrid with multiple checkbox:codes in attachment

for each checkbox for example:dynamic i have the following item:PHP,ASP,ASP.NET

and for static checkbox i have following item:jpg,gif,css

when the user tick the dynamic checkbox, strings that contain the following item will be chosen.

can u help me how to do this??

thanks for your time...

wvxvw
02-17-2009, 12:31 PM
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
applicationComplete="applicationCompleteHandler()">
<mx:Script>
<![CDATA[
import flash.events.MouseEvent;
import LogReader;
import mx.controls.CheckBox;

private var sourceArray:Array = [];

private function applicationCompleteHandler():void
{
var stringToSplit:String = "92.37.121.146 - - ";
stringToSplit += "[31/Oct/2008:02:27:27 +0800] GET ";
stringToSplit += "/bppk_en/login/login.php HTTP/1.1 ";
stringToSplit += "200 3736 http://www.bppk.gov.my/login/";
stringToSplit += "login.php?msj=You%20Have%20Been%20Force";
stringToSplit += "d%20to%20Logout Mozilla/5.0 (Windows; ";
stringToSplit += "U; Windows NT 5.1; en-US; rv:1.9.0.3) ";
stringToSplit += "Gecko/2008092417 Firefox/3.0.3 (.NET CLR 3.5.30729) ";
var result:Array = stringToSplit.split(" ");
var logReader:LogReader = new LogReader();
logReader.ip = result[0];
logReader.date = result[3] + result[4];
logReader.method = result[5];
logReader.information = result[6] + result[7];
logReader.status = result[8];
logReader.request = result[10];
sourceArray.push(logReader);

logReader = logReader.clone();
logReader.request = "http://www.example.com/foo.aspx?foo=blah";
sourceArray.push(logReader);

logReader = logReader.clone();
logReader.request = "http://www.example.com/foo.jpeg";
sourceArray.push(logReader);

logReader = logReader.clone();
logReader.request = "http://www.example.com/foo.GIF";
sourceArray.push(logReader);

logReader = logReader.clone();
logReader.request = "http://www.example.com/foo.php5?foo=blah";
sourceArray.push(logReader);
dp = XMLList(sourceArray.join(""));
}

private function filterOnRequestType(requestType:String):void
{
var lt:int = sourceArray.length;
dp = null;
while (lt--)
{
trace((sourceArray[lt] as LogReader).requestFileFormat());
if ((sourceArray[lt] as LogReader).requestFileFormat() ==
requestType)
{
if (!dp) dp = XMLList(sourceArray[lt]);
else dp += XML(sourceArray[lt]);
}
}
}

private function images_clickHandler(event:MouseEvent):void
{
if ((event.target as CheckBox).selected)
{
filterOnRequestType(LogReader.IMAGE);
} else {
dp = XMLList(sourceArray.join(""));
}
}
]]>
</mx:Script>

<mx:XMLList id="dp"/>

<mx:CheckBox label="PHP"/>
<mx:CheckBox
id="images"
label="Images"
click="images_clickHandler(event)" />
<mx:CheckBox label="ASP"/>
<mx:CheckBox label="Others"/>

<mx:DataGrid
width="749"
height="263"
editable="false"
enabled="false"
dataProvider="{dp}">

<mx:columns>
<mx:DataGridColumn headerText="IP Address" dataField="ip" width="100"/>
<mx:DataGridColumn headerText="Date" dataField="date" width="200"/>
<mx:DataGridColumn headerText="Method" dataField="method" width="60"/>
<mx:DataGridColumn headerText="Information" dataField="information" width="210"/>
<mx:DataGridColumn headerText="Status" dataField="status" width="60"/>
<mx:DataGridColumn headerText="Request" dataField="request" width="600"/>


</mx:columns>
</mx:DataGrid>
</mx:Application>
But you'll need to add filtering / change it a bit for different checkboxes, this is only an example...
package
{

/**
* LogReader class.
* @author wvxvw
*/
public class LogReader
{
public static const PHP:String = "php";
public static const ASP:String = "asp";
public static const IMAGE:String = "image";
public static const UNDEFINED:String = "undefined";

private static const EXTENSION_PHP:RegExp = /\.php\d?(\?|$)/gi;
private static const EXTENSION_ASP:RegExp = /\.aspx?(\?|$)/gi;
private static const EXTENSION_IMAGE:RegExp = /\.(bmp|png|jpg|jpeg|gif)?$/gi;

public var ip:String;
public var date:String;
public var method:String;
public var information:String;
public var status:String;
public var request:String;

public function LogReader(ip:String = null, date:String = null,
method:String = null, information:String = null,
status:String = null, request:String = null)
{
super();
this.ip = ip;
this.date = date;
this.method = method;
this.information = information;
this.status = status;
this.request = request;
}

public function requestFileFormat():String
{
if (request.match(EXTENSION_PHP).length) return PHP;
if (request.match(EXTENSION_ASP).length) return ASP;
if (request.match(EXTENSION_IMAGE).length) return IMAGE;
return UNDEFINED;
}

public function clone():LogReader
{
return new LogReader(ip, date, method, information,
status, request);
}

public function toXML():XML
{
return(
<logReader>
<ip>{ip}</ip>
<date>{date}</date>
<method>{method}</method>
<information>{information}</information>
<status>{status}</status>
<request>{request}</request>
</logReader>);
}

public function toString():String
{
return toXML().toXMLString();
}
}

}

wvxvw
02-24-2009, 10:07 AM
private static const EXTENSION_PHP:RegExp = /\.php\d?(\?|$)/gi;
Ah... This must be
private static const EXTENSION_PHP:RegExp = /\.php\d*(\W|$)/gi;
And this:
private static const EXTENSION_IMAGE:RegExp = /\.(bmp|png|jpg|jpeg|gif)?$/gi;
should be:
private static const EXTENSION_IMAGE:RegExp = /\.(bmp|png|jpg|jpeg|gif)?(\W|$)/gi;

wvxvw
02-25-2009, 06:16 AM
You allready have that covered...
return UNDEFINED;
If requestFileFormat returns "undefined" - that means it's some format it cannot recognize. i.e. "other".

wvxvw
02-25-2009, 09:49 PM
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
applicationComplete="applicationCompleteHandler()">
<mx:Script>
<![CDATA[
import flash.events.MouseEvent;
import LogReader;
import mx.controls.CheckBox;

private var sourceArray:Array = [];
private var checkboxesArray:Array = [];

private function applicationCompleteHandler():void
{
var stringToSplit:String = "92.37.121.146 - - ";
stringToSplit += "[31/Oct/2008:02:27:27 +0800] GET ";
stringToSplit += "/bppk_en/login/login.php HTTP/1.1 ";
stringToSplit += "200 3736 http://www.bppk.gov.my/login/";
stringToSplit += "login.php?msj=You%20Have%20Been%20Force";
stringToSplit += "d%20to%20Logout Mozilla/5.0 (Windows; ";
stringToSplit += "U; Windows NT 5.1; en-US; rv:1.9.0.3) ";
stringToSplit += "Gecko/2008092417 Firefox/3.0.3 (.NET CLR 3.5.30729) ";
var result:Array = stringToSplit.split(" ");
var logReader:LogReader = new LogReader();
logReader.ip = result[0];
logReader.date = result[3] + result[4];
logReader.method = result[5];
logReader.information = result[6] + result[7];
logReader.status = result[8];
logReader.request = result[10];
sourceArray.push(logReader);

logReader = logReader.clone();
logReader.request = "http://www.example.com/foo.aspx?foo=blah";
sourceArray.push(logReader);

logReader = logReader.clone();
logReader.request = "http://www.example.com/foo.jpeg";
sourceArray.push(logReader);

logReader = logReader.clone();
logReader.request = "http://www.example.com/foo.GIF";
sourceArray.push(logReader);

logReader = logReader.clone();
logReader.request = "http://www.example.com/foo.php5?foo=blah";
sourceArray.push(logReader);

logReader = logReader.clone();
logReader.request = "http://www.example.com/foo.jsp";
sourceArray.push(logReader);

dp = XMLList(sourceArray.join(""));
checkboxesArray = [php, asp, images, other];
}

private function filterOnRequestType(requestTypes:Array):void
{
var lt:int = sourceArray.length;
var currentType:String;
dp = null;
while (lt--)
{
currentType = (sourceArray[lt] as LogReader).requestFileFormat();
if (requestTypes.indexOf((currentType)) > -1)
{
if (!dp) dp = XMLList(sourceArray[lt]);
else dp += XML(sourceArray[lt]);
}
}
}

private function checkbox_clickHandler(event:MouseEvent):void
{
var requestTypes:Array = [];
for each(var cb:CheckBox in checkboxesArray)
{
if (cb.selected)
{
switch (cb)
{
case checkboxesArray[0]:
requestTypes.push(LogReader.PHP);
break;
case checkboxesArray[1]:
requestTypes.push(LogReader.ASP);
break;
case checkboxesArray[2]:
requestTypes.push(LogReader.IMAGE);
break;
case checkboxesArray[3]:
requestTypes.push(LogReader.UNDEFINED);
break;
default:
trace("You've been doing something wrong...");
break;
}
}
}
if (requestTypes.length)
{
filterOnRequestType(requestTypes);
} else {
dp = XMLList(sourceArray.join(""));
}
}
]]>
</mx:Script>

<mx:XMLList id="dp"/>

<mx:CheckBox
id="php"
label="PHP"
click="checkbox_clickHandler(event)"/>
<mx:CheckBox
id="images"
label="Images"
click="checkbox_clickHandler(event)" />
<mx:CheckBox
id="asp"
label="ASP"
click="checkbox_clickHandler(event)"/>
<mx:CheckBox
id="other"
label="Other"
click="checkbox_clickHandler(event)"/>

<mx:DataGrid
width="749"
height="263"
editable="false"
enabled="false"
dataProvider="{dp}">

<mx:columns>
<mx:DataGridColumn headerText="IP Address" dataField="ip" width="100"/>
<mx:DataGridColumn headerText="Date" dataField="date" width="200"/>
<mx:DataGridColumn headerText="Method" dataField="method" width="60"/>
<mx:DataGridColumn headerText="Information" dataField="information" width="210"/>
<mx:DataGridColumn headerText="Status" dataField="status" width="60"/>
<mx:DataGridColumn headerText="Request" dataField="request" width="600"/>


</mx:columns>
</mx:DataGrid>
</mx:Application>
package
{

/**
* LogReader class.
* @author wvxvw
*/
public class LogReader
{
public static const PHP:String = "php";
public static const ASP:String = "asp";
public static const IMAGE:String = "image";
public static const UNDEFINED:String = "undefined";

private static const EXTENSION_PHP:RegExp = /\.php\d*(\?|$|\W)/gi;
private static const EXTENSION_ASP:RegExp = /\.aspx?(\?|$|\s)/gi;
private static const EXTENSION_IMAGE:RegExp = /\.(bmp|png|jpg|jpeg|gif)?($|\W)/gi;

public var ip:String;
public var date:String;
public var method:String;
public var information:String;
public var status:String;
public var request:String;

public function LogReader(ip:String = null, date:String = null,
method:String = null, information:String = null,
status:String = null, request:String = null)
{
super();
this.ip = ip;
this.date = date;
this.method = method;
this.information = information;
this.status = status;
this.request = request;
}

public function requestFileFormat():String
{
if (request.match(EXTENSION_PHP).length) return PHP;
if (request.match(EXTENSION_ASP).length) return ASP;
if (request.match(EXTENSION_IMAGE).length) return IMAGE;
return UNDEFINED;
}

public function clone():LogReader
{
return new LogReader(ip, date, method, information,
status, request);
}

public function toXML():XML
{
return(
<logReader>
<ip>{ip}</ip>
<date>{date}</date>
<method>{method}</method>
<information>{information}</information>
<status>{status}</status>
<request>{request}</request>
</logReader>);
}

public function toString():String
{
return toXML().toXMLString();
}
}

}

wvxvw
02-26-2009, 09:34 AM
Not true... it does recognize it... just tested =/ Maybe you have both regexp for PHP and /\.(php|asp|aspx|pl|jsp)d*(\?|$|\W)/gi and then you test for PHP extension first?