dropdown to filter table records

7 views
Skip to first unread message

Bruce

unread,
Jun 23, 2009, 10:06:17 PM6/23/09
to asp-ajaxed
I am new to ajaxed but I'm hoping it will help me in my devlopment
work. I am trying to build a page that displays a list of records
from a table called campaign. I also want to put a dropdown on the
page with the options "ALL", "Active", and "Inactive". When the user
chooses one of the options in the dropdown, I want the records in the
table to be filtered depending on what was selected. The table
displays the first time but disappears on callback. From the logs I
can see that the select query isn't run on callback for some reason.
Here is my code:

<!--#include virtual="/ajaxed/ajaxed.asp"-->
<!--#include virtual="../ajaxed/class_dropdown/dropdown.asp"-->
<!--#include virtual="/ajaxed/class_datatable/datatable.asp"-->

<%
set dt = new Datatable
set page = new AjaxedPage
page.draw()

sub init()
lib.logger.info "init() START"

dt.name = "campaignList"
dt.fullsearch = false
dt.sql = "SELECT * FROM campaign where active = " & selectedStatus
()
call dt.newColumn("campaignid", "Id")
call dt.newColumn("campaignname", "Name")
call dt.newColumn("active", "Active")
dt.sort = "campaignid"
dt.recsPerPage = 20

lib.logger.info "init() END"
end sub

sub callback(a)
lib.logger.info "callback() START"

dt.draw()

lib.logger.info "callback() END"
end sub

sub drawStatusDD()
lib.logger.info "drawStatusDD() START"

set dcText = (new DataContainer)(array("Active", "Inactive"))
set dcValues = (new DataContainer)(array(1, 0))
with new Dropdown
.name = "statusDD"
.datasource = dcText.data
.valuesDatasource = dcValues.data
.selectedValue = selectedStatus()
.attributes = "onchange=""ajaxed.callback('GetCampaigns',
'campaignListx')"""
.draw()
end with

lib.logger.info "drawStatusDD() END"
end sub

sub pagePart_GetCampaigns()
lib.logger.info "pagePart_GetCampaigns() START"

dt.draw()

lib.logger.info "pagePart_GetCampaigns() END"
end sub

function selectedStatus()
lib.logger.info "selectedStatus() START"

status = page.RFP("statusDD", -1)
if status = -1 then
status = 0
end if

lib.logger.info "status is " & status

selectedStatus = status

lib.logger.info "selectedStatus() END"
end function

sub main()
lib.logger.info "main() START"

%>

<form id="frm">
<div><% drawStatusDD() %></div>
<div id="campaignListx"><% pagePart_GetCampaigns() %></div>
</form>

<%
lib.logger.info "main() END"
end sub
%>

Michal Gabrukiewicz

unread,
Jun 25, 2009, 12:04:44 PM6/25/09
to asp-ajaxed
Dear bruce,

your code is nice! the only thing is that the datatable cant be used within a pagepart ... you need to call the dt.draw() in your main method directly ...
in your case i would suggest using a common postback if the dropdown gets changed .. so you would have a page refresh which should be fine.

.attributes = "onchange=""$('frm').submit()"""

btw you can refactor the following


status = page.RFP("statusDD", -1)
  if status = -1 then
      status = 0
  end if

into

status = page.RFP("statusDD", 0)

it would mean the same....
i like the way you coded .. exactly how it should be done with ajaxed.

good luck
michal 
--
michal
Reply all
Reply to author
Forward
0 new messages