PDA

View Full Version : Problem displaying next page of results in datagrid


haleh
06-01-2006, 02:28 AM
Hi,

I am using pageable results to populate a dataset that is bound to a datagrid. I followed the example on amfphp.org and have been able to successful populate my datagrid with the first page of results. However, when I scroll down in my datagrid the next page of results doesn't appear, just empty spaces where they should appear. My NetConnection debugger is showing that the next 3 pages of results are successfully called/returned, so I don't know why they aren't appearing in the datagrid. Maybe I am missing something. Any suggestions appreciated....

Here is my code:

Flash:

function getSummary() {
var pc:PendingCall = service.getSummary();
pc.responder = new RelayResponder(this, "handleGetSummary", "handleRemotingError");
}


function handleGetSummary(re:ResultEvent) {
re.result.setDeliveryMode("page", 10, 0);
ds_gems.dataProvider = re.result;
grid.dataProvider = ds_gems.dataProvider;
var src = new mx.data.binding.EndPoint();
var dest = new mx.data.binding.EndPoint();
src.component = dataSet;
src.property = "dataProvider";
src.event = "modelChanged";
dest.component = dataGrid;
dest.property = "dataProvider";
dest.event = "modelChanged";
new Binding(src, dest,undefined,true);

grid.removeAllColumns();
grid.columnNames = ["Id","Title","Category","Created"];
}
getSummary();



PHP:


....
var $countQuery; //used for paging results



"getSummary" => array(
"description" => "gets a summary of most relevant gem info", "access" => "remote",
"returntype" => "recordset",
"pagesize" => "10"
)

function getSummary($offset=0, $limit=10) {

$query = "SELECT pm.pod_id as 'Id', pc.pod_title as 'Title', ps.pod_subcat_name as 'Sub-Category', pcs.pod_cat_subcat_id as 'cat_sub_id', pcs.pod_category_id as 'cat_id', pcat.pod_cat_name as 'Category', pm.created_datetime as 'Created', pm.pod_status as 'Pod Status', pm.nonFlash_status as 'Pod Non-Flash Status', pm.images_folder as 'images_folder' FROM pod_main as pm, pod_content as pc, pod_subcategory as ps, pod_category as pcat, pod_category_subcategory as pcs WHERE pm.content_id = pc.content_id AND pm.pod_cat_subcat_id = pcs.pod_cat_subcat_id AND pcs.pod_subcat_id = ps.pod_subcat_id AND pcs.pod_category_id = pcat.pod_category_id AND pm.pod_status != 3 ORDER BY pm.pod_status LIMIT $offset, $limit";

$result = mysql_query($query);

NetDebug::trace($query);
NetDebug::trace(mysql_error());
$this->countQuery = sprintf("SELECT COUNT(*) AS recordCount FROM pod_main WHERE pod_status != 3");
return $result;
}
function getSummary_count() { //allows for record paging
$query = mysql_query($this->countQuery);
$row = mysql_fetch_assoc($query);
return $row['recordCount'];
}

haleh
06-01-2006, 09:30 PM
Ok, the problem seemed to be the fact that the datagrid wasn't bound directly to the recordset but instead to the dataset. When I removed this line of code:

grid.dataProvider = ds_gems.dataProvider;

and replaced it with:

grid.dataProvider = re.result;

paging worked. BUT, now sorting isn't working on the datagrid. At all. What a pain!

This is making me rethink my design, i.e. RecordSet->DataSet->DataGrid. Why do I need the dataset when I have a recordset that holds the data and allows me to manipulate it? If something changes in the recordset I can listen for it and send the changes back to my php class to update the database, correct?

So question: what are pros/cons of using
RecordSet->DataSet->DataGrid vs. RecordSet->DataGrid ??