Over the past couple of weeks I have been writing quick tutorials on extending the built in AJAX components. Today I would like to show you an example that I believe everyone is going to find useful. Once you have a data grid displaying your data there are usually 2 key operations users will perform. The 1st is pagination of records which is built into the grid and is pretty easy to use. The 2nd is filtering or how can I find exactly what I am looking for without browsing all of the records. Most filter examples I have seen where built outside of the grid but I want to run through an example that builds a filter into the grid.
Before we get started I think we should take a look at the outcome, this way the tutorial makes a little more sense. I do not have 8 running so I will have to explain this using pictures. First we have a list of artists and I provide the user a way to filter the artists by what state they are in. When the state is selected the grid is updated.
This demo like the others uses the cfartgallery data source that ships with CF so you should be able to run this example without any setup. The first thing we need to do is run our query and display our grid. This is pretty basic and you should understand what is going on here.
ColdFISH is developed by Jason Delmore. Source code and license information available at coldfish.riaforge.org
<cfquery name="getArtists" datasource="cfartgallery">
SELECT artistId, firstname, lastname, address, city, state, postalcode, email
FROM Artists
</cfquery>
<cfset args = structNew()>
<cfset args.name = "ArtistGrid">
<cfset args.format = "html">
<cfset args.query = "getArtists">
<cfset args.stripeRows = true>
<cfset args.selectColor = "##D9E8FB">
<cfset args.width = 600>
<cfform>
<cfgrid attributeCollection="#args#">
<cfgridcolumn name="artistid" display="false">
<cfgridcolumn name="firstname" header="First Name">
<cfgridcolumn name="lastname" header="Last Name">
<cfgridcolumn name="email" header="Email Address">
<cfgridcolumn name="address" header="Address">
<cfgridcolumn name="city" header="City">
<cfgridcolumn name="state" header="State">
<cfgridcolumn name="postalcode" header="Zip">
</cfgrid>
</cfform>
1<cfquery name="getArtists" datasource="cfartgallery">
2 SELECT artistId, firstname, lastname, address, city, state, postalcode, email
3 FROM Artists
4 </cfquery>
5
6 <cfset args = structNew()>
7 <cfset args.name = "ArtistGrid">
8 <cfset args.format = "html">
9 <cfset args.query = "getArtists">
10 <cfset args.stripeRows = true>
11 <cfset args.selectColor = "##D9E8FB">
12 <cfset args.width = 600>
13
14 <cfform>
15 <cfgrid attributeCollection="#args#">
16 <cfgridcolumn name="artistid" display="false">
17 <cfgridcolumn name="firstname" header="First Name">
18 <cfgridcolumn name="lastname" header="Last Name">
19 <cfgridcolumn name="email" header="Email Address">
20 <cfgridcolumn name="address" header="Address">
21 <cfgridcolumn name="city" header="City">
22 <cfgridcolumn name="state" header="State">
23 <cfgridcolumn name="postalcode" header="Zip">
24 </cfgrid>
25 </cfform>
Now that our grid is setup we need to call a function post setup. We can do this using the ajaxOnLoad tag.
ColdFISH is developed by Jason Delmore. Source code and license information available at coldfish.riaforge.org
<cfset ajaxOnLoad("init")>
1<cfset ajaxOnLoad("init")>
I am going to be using some toolbar and button code that is a part of the Ext framework. To make use of those classes we must import them.
ColdFISH is developed by Jason Delmore. Source code and license information available at coldfish.riaforge.org
<script type="text/javascript" src="/CFIDE/scripts/ajax/ext/package/toolbar/toolbar.js"></script>
<script type="text/javascript" src="/CFIDE/scripts/ajax/ext/package/button/button.js"></script>
1<script type="text/javascript" src="/CFIDE/scripts/ajax/ext/package/toolbar/toolbar.js"></script>
2 <script type="text/javascript" src="/CFIDE/scripts/ajax/ext/package/button/button.js"></script>
Now that we setup our init method that will automatically get called after the page is setup. We need to get the grid component and we can use the built in method to do so. Next if you read my custom toolbar article you know the next couple of lines grabs the header panel and creates a toolbar on it.
ColdFISH is developed by Jason Delmore. Source code and license information available at coldfish.riaforge.org
<script type="text/javascript">
function init(){
grid = ColdFusion.Grid.getGridObject("ArtistGrid");
var gridHead = grid.getView().getHeaderPanel(true);
var tbar = new Ext.Toolbar(gridHead);
}
</script>
1<script type="text/javascript">
2 function init(){
3 grid = ColdFusion.Grid.getGridObject("ArtistGrid");
4 var gridHead = grid.getView().getHeaderPanel(true);
5 var tbar = new Ext.Toolbar(gridHead);
6
7 }
8
9 </script>
Now we need to build our combo box that will be used as a filter. If you are not familiar with Ext you may want to look at the docs. A Combo box can loaded using json but for this example to keep things simple I am just going to load the box inline. The empty text attribute the text to display in the box while now selection is made.
ColdFISH is developed by Jason Delmore. Source code and license information available at coldfish.riaforge.org
cb = new Ext.form.ComboBox({
id:"stateFilter",
emptyText:"Filter By State",
mode:"local",
triggerAction:"all",
displayField:"text",
valueField:"value",
store:new Ext.data.SimpleStore({
fields: ["value", "text"],
data: [
["CA","California"],
["CO","Colorado"],
["FL","Florida"],
["GA","Georgia"],
["NY","New York"],
["SD","South Dakota"]
]
})
});
1cb = new Ext.form.ComboBox({
2 id:"stateFilter",
3 emptyText:"Filter By State",
4 mode:"local",
5 triggerAction:"all",
6 displayField:"text",
7 valueField:"value",
8 store:new Ext.data.SimpleStore({
9 fields: ["value", "text"],
10 data: [
11 ["CA","California"],
12 ["CO","Colorado"],
13 ["FL","Florida"],
14 ["GA","Georgia"],
15 ["NY","New York"],
16 ["SD","South Dakota"]
17 ]
18 })
19 });
Now that we have created our combo box we need to add an event listener. What we are saying is when a user selects something do the following. Using the grid reference we created at the top of the function we can grab the grids store (datasource) and use a built in method filter. The filter method takes two arguments, the column you want to filter on and the value you want to to filter.
ColdFISH is developed by Jason Delmore. Source code and license information available at coldfish.riaforge.org
cb.addListener("select",function(combo,record,index){
var state = record.data.value;
//filter the records
grid.getDataSource().filter("STATE",state);
});
1cb.addListener("select",function(combo,record,index){
2var state = record.data.value;
3 //filter the records
4 grid.getDataSource().filter("STATE",state);
5});
The filter is now setup, now we just need to add it to our toolbar. The first line ads a spacer in so that our toolbar items are right aligned. Next I add a button that can be used to remove the filter. After a state is selected this will give us a way to return back to the grids original state. We will look at the event handler for this button in a second. Then next we create a separator between our button and combo box and finally add our combo box.
ColdFISH is developed by Jason Delmore. Source code and license information available at coldfish.riaforge.org
Ext.fly(tbar.addSpacer().getEl().parentNode).setStyle('width', '100%');
tbar.addButton({
text:"Remove Filter",
icon:"plugin.png",
cls:"x-btn-text-icon",
tooltip:"Remove Filter",
handler:removeFilter
});
tbar.add(new Ext.Toolbar.Separator());
tbar.add(cb);
1Ext.fly(tbar.addSpacer().getEl().parentNode).setStyle('width', '100%');
2 tbar.addButton({
3 text:"Remove Filter",
4 icon:"plugin.png",
5 cls:"x-btn-text-icon",
6 tooltip:"Remove Filter",
7 handler:removeFilter
8 });
9tbar.add(new Ext.Toolbar.Separator());
10tbar.add(cb);
Finally here is how the grids original state is restored. The store has a method for removing the filter and I simply reset the combo box the empty text is restored.
ColdFISH is developed by Jason Delmore. Source code and license information available at coldfish.riaforge.org
function removeFilter(){
store = grid.getDataSource()
//remove the data filter
store.clearFilter();
//clear the value of the combo box
cb.clearValue();
//reset it so empty text shows up
cb.reset();
}
1function removeFilter(){
2 store = grid.getDataSource()
3 //remove the data filter
4 store.clearFilter();
5 //clear the value of the combo box
6 cb.clearValue();
7 //reset it so empty text shows up
8 cb.reset();
9 }
Hopefully this tutorial will show you that there is a great deal of customizing that can go into the grids. Hopefully this will inspire you to create your own filters. If you have any comments or questions just let me know. Plus I am looking for more ideas on extending the grid. If you have something you are trying to accomplish but not sure how just let me know. Here is the full code for the tutorial.
ColdFISH is developed by Jason Delmore. Source code and license information available at coldfish.riaforge.org
<html>
<head>
<title>Grid Filter Exmaple</title>
<script type="text/javascript" src="/CFIDE/scripts/ajax/ext/package/toolbar/toolbar.js"></script>
<script type="text/javascript" src="/CFIDE/scripts/ajax/ext/package/button/button.js"></script>
<script type="text/javascript">
function init(){
grid = ColdFusion.Grid.getGridObject("ArtistGrid");
var gridHead = grid.getView().getHeaderPanel(true);
var tbar = new Ext.Toolbar(gridHead);
cb = new Ext.form.ComboBox({
id:"stateFilter",
emptyText:"Filter By State",
mode:"local",
triggerAction:"all",
displayField:"text",
valueField:"value",
store:new Ext.data.SimpleStore({
fields: ["value", "text"],
data: [
["CA","California"],
["CO","Colorado"],
["FL","Florida"],
["GA","Georgia"],
["NY","New York"],
["SD","South Dakota"]
]
})
});
cb.addListener("select",function(combo,record,index){
var state = record.data.value;
//filter the records
grid.getDataSource().filter("STATE",state);
});
Ext.fly(tbar.addSpacer().getEl().parentNode).setStyle('width', '100%');
tbar.addButton({
text:"Remove Filter",
icon:"plugin.png",
cls:"x-btn-text-icon",
tooltip:"Remove Filter",
handler:removeFilter
});
tbar.add(new Ext.Toolbar.Separator());
tbar.add(cb);
console.log(Ext);
}
function removeFilter(){
store = grid.getDataSource()
//remove the data filter
store.clearFilter();
//clear the value of the combo box
cb.clearValue();
//reset it so empty text shows up
cb.reset();
}
</script>
</head>
<body>
<link href="/CFIDE/scripts/ajax/ext/resources/css/ytheme-aero.css" rel="stylesheet" type="text/css">
<cfquery name="getArtists" datasource="cfartgallery">
SELECT artistId, firstname, lastname, address, city, state, postalcode, email
FROM Artists
</cfquery>
<cfset args = structNew()>
<cfset args.name = "ArtistGrid">
<cfset args.format = "html">
<cfset args.query = "getArtists">
<cfset args.stripeRows = true>
<cfset args.selectColor = "##D9E8FB">
<cfset args.width = 600>
<cfform>
<cfgrid attributeCollection="#args#">
<cfgridcolumn name="artistid" display="false">
<cfgridcolumn name="firstname" header="First Name">
<cfgridcolumn name="lastname" header="Last Name">
<cfgridcolumn name="email" header="Email Address">
<cfgridcolumn name="address" header="Address">
<cfgridcolumn name="city" header="City">
<cfgridcolumn name="state" header="State">
<cfgridcolumn name="postalcode" header="Zip">
</cfgrid>
</cfform>
<cfset ajaxOnLoad("init")>
</body>
</html>
1<html>
2<head>
3 <title>Grid Filter Exmaple</title>
4
5 <script type="text/javascript" src="/CFIDE/scripts/ajax/ext/package/toolbar/toolbar.js"></script>
6 <script type="text/javascript" src="/CFIDE/scripts/ajax/ext/package/button/button.js"></script>
7
8 <script type="text/javascript">
9 function init(){
10 grid = ColdFusion.Grid.getGridObject("ArtistGrid");
11 var gridHead = grid.getView().getHeaderPanel(true);
12 var tbar = new Ext.Toolbar(gridHead);
13
14 cb = new Ext.form.ComboBox({
15 id:"stateFilter",
16 emptyText:"Filter By State",
17 mode:"local",
18 triggerAction:"all",
19 displayField:"text",
20 valueField:"value",
21 store:new Ext.data.SimpleStore({
22 fields: ["value", "text"],
23 data: [
24 ["CA","California"],
25 ["CO","Colorado"],
26 ["FL","Florida"],
27 ["GA","Georgia"],
28 ["NY","New York"],
29 ["SD","South Dakota"]
30 ]
31 })
32 });
33
34 cb.addListener("select",function(combo,record,index){
35 var state = record.data.value;
36 //filter the records
37 grid.getDataSource().filter("STATE",state);
38 });
39
40 Ext.fly(tbar.addSpacer().getEl().parentNode).setStyle('width', '100%');
41 tbar.addButton({
42 text:"Remove Filter",
43 icon:"plugin.png",
44 cls:"x-btn-text-icon",
45 tooltip:"Remove Filter",
46 handler:removeFilter
47 });
48 tbar.add(new Ext.Toolbar.Separator());
49 tbar.add(cb);
50 console.log(Ext);
51 }
52 function removeFilter(){
53 store = grid.getDataSource()
54 //remove the data filter
55 store.clearFilter();
56 //clear the value of the combo box
57 cb.clearValue();
58 //reset it so empty text shows up
59 cb.reset();
60 }
61 </script>
62</head>
63<body>
64
65 <link href="/CFIDE/scripts/ajax/ext/resources/css/ytheme-aero.css" rel="stylesheet" type="text/css">
66
67
68 <cfquery name="getArtists" datasource="cfartgallery">
69 SELECT artistId, firstname, lastname, address, city, state, postalcode, email
70 FROM Artists
71 </cfquery>
72
73 <cfset args = structNew()>
74 <cfset args.name = "ArtistGrid">
75 <cfset args.format = "html">
76 <cfset args.query = "getArtists">
77 <cfset args.stripeRows = true>
78 <cfset args.selectColor = "##D9E8FB">
79 <cfset args.width = 600>
80
81 <cfform>
82 <cfgrid attributeCollection="#args#">
83 <cfgridcolumn name="artistid" display="false">
84 <cfgridcolumn name="firstname" header="First Name">
85 <cfgridcolumn name="lastname" header="Last Name">
86 <cfgridcolumn name="email" header="Email Address">
87 <cfgridcolumn name="address" header="Address">
88 <cfgridcolumn name="city" header="City">
89 <cfgridcolumn name="state" header="State">
90 <cfgridcolumn name="postalcode" header="Zip">
91 </cfgrid>
92 </cfform>
93
94 <cfset ajaxOnLoad("init")>
95
96</body>
97</html>
This entry was posted on March 10, 2008 at 10:38 AM and has received 14638 views. Comments 38 |
Print this entry.
#1 by Samer Salameh on 3/11/08 - 6:53 AM
Can you update the example to make Combo box loaded using json?
#2 by Frank Wheatley on 3/11/08 - 9:23 AM
cbCategory = new Ext.form.ComboBox({
id:"categoryFilter",
emptyText:"Fund Category",
mode:"local",
triggerAction:"all",
displayField:"text",
valueField:"value",
store:new Ext.data.SimpleStore({
fields: ["value", "text"],
data: [
<cfoutput query="qFndCat">
["#fndcatid#","#fndcatdes#"]<cfif qFndCat.currentrow LT qFndCat.recordcount>,</cfif>
</cfoutput>
]
})
});
Now I need to figure out how to filter on multiple fields
#3 by Dan Vega on 3/11/08 - 9:28 AM
#4 by Frank Wheatley on 3/11/08 - 1:18 PM
The filtering needs to be on multiple columns. I may want to select only Vangard, Large Cap funds.
I was able to do this by adding a bind to a cfc on the cfgrid. However, I'd like to do it without a trip to the db after each selection. The query is somewhat complex.
#5 by Dan Vega on 3/11/08 - 1:21 PM
#6 by Frank Wheatley on 3/11/08 - 1:32 PM
I used the bind cfc and paging, but it called the cfc every time the filter or sort changed. This method seem much more efficient if possible.
BTW - thanks for the example and replies.
#7 by Dan Vega on 3/11/08 - 1:36 PM
#8 by Brian on 5/12/08 - 10:12 AM
#9 by Dan Vega on 5/12/08 - 10:37 AM
#10 by Brian on 5/12/08 - 10:44 AM
#11 by Brian on 5/21/08 - 2:40 PM
I've continued to try to work this master-detail app, but I'm hung up on 2 fronts.
1) Passing the clicked on key from the datagrid master to a CFC for populating the detail fields. However, I can get the data from the grid, including the key to show up in the detail area and I can invoke the CFC with a set key value.
2) My javascript form submittals are failing, where I try to submit new search data posting the form to the current page. However I can bind the grid to some of the search fields and click the refresh in the grid and it updates the grid with the new parameters. Perhaps your example will clarify what I'm doing wrong here.
#12 by Dan Vega on 6/5/08 - 10:47 AM
#13 by Brian on 6/5/08 - 2:11 PM
I am having trouble finding something so I can provide a message to the user regarding the status of a request. The little icon on the grid is not adequate. Ideally something like a slider displaying % complete or at least "please wait". I saw grid has a loadmask.msg attribute, but have not got it to work.
Also do you have a good example or reference for doing the search within search results for cfgrid, but using the form outside the grid?
#14 by knk on 10/16/08 - 10:51 AM
<cfquery name="ListAllContent" datasource="#Request.Config.DSN.Primary#" >
SELECT
m.Id AS id,
m.LastName + ', ' + m.FirstName AS FullName,
m.CompanyId,
m.EmailAddress,
m.WorkPhone,
c.Name AS CompanyName,
p.Name AS PositionName,
acstat.Name AS AccountStatus
FROM
nma_Members AS m INNER JOIN
nma_Companies AS c ON m.CompanyId = c.Id INNER JOIN
nma_AccountStatuses AS acstat ON m.AccountStatusId = acstat.Id INNER JOIN
nma_Positions AS p ON m.PositionId = p.Id
<!--- WHERE
(acstat.Id <> '4')
AND
(acstat.Id <> '3') --->
</cfquery>
<cfset args = structNew()>
<cfset args.name = "MemberGrid">
<cfset args.format = "html">
<cfset args.align="middle">
<cfset args.query = "ListAllContent">
<cfset args.stripeRows = true>
<cfset args.selectColor = "##D9E8FB">
<cfset args.width = 600>
<cfset args.sort = true>
<cfset args.pagesize="25">
<cfform>
<cfgrid attributeCollection="#args#">
<cfgridcolumn name="id" display="no"/>
<cfgridcolumn name="PositionName" header="Role" width="50">
<cfgridcolumn name="FullName" header="Full Name" width="150">
<cfgridcolumn name="CompanyName" header="Company" width="170">
<cfgridcolumn name="EmailAddress" header="Email Address" width="180">
<cfgridcolumn name="AccountStatus" header="Account Status" width="50">
</cfgrid>
</cfform>
cb = new Ext.form.ComboBox({
id:"AccountStatus",
emptyText:"Filter By Account Status",
mode:"local",
triggerAction:"all",
displayField:"AccountStatus",
valueField:"AccountStatusId",
store:new Ext.data.SimpleStore({
fields: ["AccountStatus", "AccountStatus"],
data: [
["1","Active"],
["2","Inactive"],
]
})
});
cb.addListener("select",function(combo,record,index){
var AccountStatusID = record.data.value;
grid.getDataSource().filter("STATE",AccountStatusId); //filter the records
});
#15 by knk on 10/16/08 - 10:55 AM
I'm not sure what to args go there
#16 by Dan Vega on 10/16/08 - 11:06 AM
grid.getDataSource().filter("STATE",AccountStatusId);
Let me know if that works for you.
#17 by knk on 10/16/08 - 2:07 PM
function init(){
grid = ColdFusion.Grid.getGridObject("MemberGrid");
//var gridFoot = grid.getView().getFooterPanel(true); //make the footer
var gridHead = grid.getView().getHeaderPanel(true); //make the header so I can add button and CB
var tbar = new Ext.Toolbar(gridHead);
cb = new Ext.form.ComboBox({
id:"AccountFilter",
emptyText:"Filter By Account Status",
mode:"local",
triggerAction:"all",
displayField:"text",
valueField:"value",
store:new Ext.data.SimpleStore({
fields: ["value", "text"],
data: [
["1","Active"],
["2","Inactive"]
]
})
});
cb.addListener("select",function(combo,record,index){
var AccountStatus = record.data.value;
var AccountStatus2 = record.data.text;
alert(AccountStatus2);
grid.getDataSource().filter("AccountStatus",AccountStatus2); //fi
//alert("ok");
});
Ext.fly(tbar.addSpacer().getEl().parentNode).setStyle('width', '100%');
tbar.addButton({
text:"Remove Filter",
icon:"plugin.png",
cls:"x-btn-text-icon",
tooltip:"Remove Filter",
handler:removeFilter
});
tbar.add(new Ext.Toolbar.Separator());
tbar.add(cb);
console.log(Ext);
}
function removeFilter(){
store = grid.getDataSource()
store.clearFilter();
cb.clearValue(); //clear the value of the combo box
cb.reset(); //reset it so empty text shows up
}
<link href="/CFIDE/scripts/ajax/ext/resources/css/ytheme-aero.css" rel="stylesheet" type="text/css">
<cfquery name="ListAllContent" datasource="#Request.Config.DSN.Primary#" >
SELECT
m.Id AS id,
m.LastName + ', ' + m.FirstName AS FullName,
m.CompanyId,
m.EmailAddress,
m.WorkPhone,
c.Name AS CompanyName,
p.Name AS PositionName,
acstat.Name AS AccountStatus,
acstat.id as StatusID
FROM
nma_Members AS m INNER JOIN
nma_Companies AS c ON m.CompanyId = c.Id INNER JOIN
nma_AccountStatuses AS acstat ON m.AccountStatusId = acstat.Id INNER JOIN
nma_Positions AS p ON m.PositionId = p.Id
<!--- WHERE
(acstat.Id <> '4')
AND
(acstat.Id <> '3') --->
</cfquery>
<cfset args = structNew()>
<cfset args.name = "MemberGrid">
<cfset args.format = "html">
<!--- <cfset args.align="middle"> --->
<cfset args.query = "ListAllContent">
<cfset args.stripeRows = true>
<cfset args.selectColor = "##D9E8FB">
<cfset args.width = 800>
<!--- <cfset args.sort = true>
<cfset args.pagesize="25"> --->
<cfform>
<cfgrid attributeCollection="#args#">
<cfgridcolumn name="id" display="false"/>
<cfgridcolumn name="StatusID" display="false"/>
<cfgridcolumn name="PositionName" header="Role" >
<cfgridcolumn name="FullName" header="Full Name" >
<cfgridcolumn name="CompanyName" header="Company" >
<cfgridcolumn name="EmailAddress" header="Email Address" >
<cfgridcolumn name="AccountStatus" header="Status" >
</cfgrid>
</cfform>
<cfset ajaxOnLoad("init")>
#18 by Dan Vega on 10/16/08 - 2:17 PM
grid.getDataSource().filter("AccountStatus",AccountStatus2);
#19 by knk on 10/16/08 - 2:56 PM
I made the change and still no filtered data appears
grid.getDataSource().filter("ACCOUNTSTATUS",AccountStatus2);
#20 by knk on 10/16/08 - 3:13 PM
var state= record.data.value;
Is this the actual data from the column on the grid? Or from the simple store?
#21 by Dan Vega on 10/16/08 - 3:19 PM
#22 by knk on 10/16/08 - 3:42 PM
#23 by knk on 10/16/08 - 3:56 PM
#24 by knk on 10/16/08 - 4:02 PM
THANKS!
#25 by knk on 10/17/08 - 12:30 PM
JS:
function init(){
grid = ColdFusion.Grid.getGridObject("MemberGrid");
//var gridFoot = grid.getView().getFooterPanel(true); //make the footer
var gridHead = grid.getView().getHeaderPanel(true); //make the header so I can add button and CB
var tbar = new Ext.Toolbar(gridHead);
cb = new Ext.form.ComboBox({
id:"AccountFilter",
emptyText:"Filter By Account Status",
mode:"local",
triggerAction:"all",
displayField:"text",
valueField:"value",
store:new Ext.data.SimpleStore({
fields: ["value", "text"],
data: [
["Active","Active"],
["Inactive","Inactive"],
["Historical","Historical"],
["Guest","Guest"],
]
})
});
cb.addListener("select",function(combo,record,index){
var AccountStatus = record.data.value;
var AccountStatus2 = record.data.text;
grid.getDataSource().filter("ACCOUNTSTATUS",AccountStatus); //fi
});
Ext.fly(tbar.addSpacer().getEl().parentNode).setStyle('width', '100%');
tbar.addButton({
text:"Remove Filter",
icon:"plugin.png",
cls:"x-btn-text-icon",
tooltip:"Remove Filter",
handler:removeFilter
});
tbar.add(new Ext.Toolbar.Separator());
tbar.add(cb);
console.log(Ext);
}
function removeFilter(){
store = grid.getDataSource()
store.clearFilter();
cb.clearValue(); //clear the value of the combo box
cb.reset(); //reset it so empty text shows up
}
CFFORM:
<cfform>
<cfgrid format="html" striperows="yes" selectcolor="##D9E8FB" sort="true" width="500" name="MemberGrid" pagesize="500" bind="cfc:#Request.Config.CustomComponentDir#.Members.getMembers({cfgridpage},{cfgridpagesize},{cfgridsortcolumn},{cfgridsortdirection})">
<cfgridcolumn name="ID" display="false"/>
<cfgridcolumn name="STATUSID" display="false"/>
<cfgridcolumn name="POSITIONAME" header="Role" >
<cfgridcolumn name="FULLNAME" header="Full Name" >
<cfgridcolumn name="COMPANYNAME" header="Company" >
<cfgridcolumn name="EMAILADDRESS" header="Email Address" >
<cfgridcolumn name="ACCOUNTSTATUS" header="Status" >
</cfgrid>
</cfform>
<cfset ajaxOnLoad("init")>
CFC:
<cfcomponent>
<cffunction name="getMembers" access="remote">
<cfargument name="page" required="yes">
<cfargument name="pageSize" required="yes">
<cfargument name="gridsortcolumn" required="yes">
<cfargument name="gridsortdirection" required="yes">
<cfquery name="ListAllContent" datasource="#Request.Config.DSN.Primary#" >
SELECT
m.Id AS id,
m.LastName + ', ' + m.FirstName AS FullName,
m.CompanyId,
m.EmailAddress,
m.WorkPhone,
c.Name AS CompanyName,
p.Name AS PositionName,
acstat.Name AS AccountStatus,
acstat.id as StatusID,
getdate() as currenttime
FROM
nma_Members AS m INNER JOIN
nma_Companies AS c ON m.CompanyId = c.Id INNER JOIN
nma_AccountStatuses AS acstat ON m.AccountStatusId = acstat.Id INNER JOIN
nma_Positions AS p ON m.PositionId = p.Id
<cfif gridsortcolumn neq ''>
order by #gridsortcolumn# #gridsortdirection#
</cfif>
</cfquery>
<cfreturn queryconvertforgrid(ListAllContent,page,pagesize)/>
</cffunction>
</cfcomponent>
#26 by Dan Vega on 10/17/08 - 1:04 PM
#27 by Frank Wheatley on 10/17/08 - 1:10 PM
this may not be the exact code
bind="cfc:#Request.Config.CustomComponentDir#.Members.getMembers({cfgridpage},{cfgridpagesize},{cfgridsortcolumn},{cfgridsortdirection},{AccountFilter})">
#28 by knk on 10/21/08 - 12:16 PM
Another question. I want to add another column to grid that has a hyperlink called Edit. Each row will have a Edit link. I can't seem to make the href attributes work correctly. I added the column on but it just displays a small line in the column I added? Any Suggestions?
Thanks
#29 by Jim Papaleo on 11/4/08 - 2:34 PM
you need to create a function:
var myf1 = function(data,cellmd,record,row,col,store) {
if(data > "") return "<a href=sodetail.cfm?key=" + data + ">" + data + "</a>";
else return data;
}
Call the function when the grid is loaded
// the init()
function init(){
grid = ColdFusion.Grid.getGridObject("ShipGrid");
cm = grid.getColumnModel();
cm.setRenderer(1,myf1);
grid.reconfigure(grid.getDataSource(),cm);
#30 by Bud Hines on 12/13/08 - 3:21 PM
On a separate note, I needed to comment out this call in my application cfc to get the data to show up: <cffunction name="onRequest">
Any help would be appreciated.
thanks,
Bud
#31 by Bonnie on 12/16/08 - 1:55 PM
I am also unalbe to see any tooltips from these 'addButton()' functions. Is this too a known IE6 problem? I am able to get the whole thing to seemingly work fine without using the console function, but I really need those tooltips.
Any advice is appreciated.
#32 by Michael on 12/18/08 - 1:16 AM
Example, I want to filter the grid based upon date and time. Currently i can filter by date, but what if i want to filter by time instead? What if i wanted to filter by date and THEN time...
Is this posisble?
#33 by icd on 2/25/09 - 11:05 AM
Code:
<script type="text/javascript">
<cfquery name="qListArtists" datasource="cfartgallery">
SELECT DISTINCT state
FROM Artists
ORDER BY state
</cfquery>
function init(){
grid = ColdFusion.Grid.getGridObject("ArtistGrid");
var gridHead = grid.getView().getHeaderPanel(true);
var tbar = new Ext.Toolbar(gridHead);
cb = new Ext.form.ComboBox({
id:"stateFilter",
emptyText:"Filter By State",
mode:"local",
triggerAction:"all",
displayField:"text",
valueField:"value",
store:new Ext.data.SimpleStore({
fields: ["value", "text"],
data: [
<cfoutput query="qListArtists">
["#state#"]<cfif qListArtists.currentrow LT qListArtists.recordcount>,</cfif>
</cfoutput>
]
})
});
cb.addListener("select",function(combo,record,index){
var state = record.data.value;
grid.getDataSource().filter("STATE",state);
});
#34 by Bonnie on 2/25/09 - 2:00 PM
#35 by Catbollu on 7/26/10 - 12:15 PM
You were working on an example to show how to click a row and show details. Is there anywhere I might see this example?
#36 by Dan Vega on 7/29/10 - 3:17 PM
#37 by Catbollu on 7/29/10 - 3:38 PM
#38 by Dan Vega on 8/2/10 - 11:05 PM
http://www.danvega.org/blog/index.cfm/2010/8/2/Sho...