Extending DatabaseItemList

Permalink
I would like to make use of the DatabaseItemList, bit cannot find a decent tutorial any place. I have managed to extend the item easily enough and can retrieve the pagination and summary info. But how do I display the results? Should I write custom code for displaying of the results?

Also, how do I display the search box? Is it possible to use this search box.

I am really quite confused on this spesific piece of functionality.

 
jordanlev replied on at Permalink Reply
jordanlev
It sounds like you've figured everything out there is to figure out with the DatabaseItemList (performing a query, and using pagination and summary). It's just an internal code thing -- it gives you raw results, but will not display those (you need to do that yourself within a block or a single_page or something like that -- where you have your own code that uses the DatabaseItemList to retrieve results, then your own code takes those results and outputs the proper HTML to display them).

What is it exactly you're trying to do?

And what do you mean "display the search box"? What search box? If you mean the built-in "Search" block, you just add the block to a page.
jaconel007 replied on at Permalink Reply 1 Attachment
I was hoping it could help me recreate a screen similar to the example attached.
jaconel007 replied on at Permalink Reply
So I have managed to create the ui quite easily by copying and pasting the elements from another single page. I am however still in the dark o how I can change the query to include only results dependent on my search keyword. I tried using
addToQuery()
, but the DatabaseItemList keeps adding
WHERE 1=1
to the back of my query, thus breaking it.

Another thing that I can not sort out is, my pagination displays correctly and it works perfectly, but the summary keeps displaying information of the first page. It does not seem to update dependent on the current page. Any ideas?
jaconel007 replied on at Permalink Reply
Ok, found out I can use the following code to apply the search.

$ul->filter('pTitle', "%keyword%", "LIKE");
mkly replied on at Permalink Best Answer Reply
mkly
I'm nuts busy but you seem to still be plugging away so maybe this will help.

On DatabaseItemList
$dl = new DatabaseItemList();
// this is the start select and join if needed
$dl->addToQuery('select something from sometable');
// this is a where with like(can also do like =, < etc)
$dl->filter('somecolumn', 'somevalue', 'like');
// Order
$dl->sortBy('somecolumn', 'asc');
// get 20 starting with the 10
$results = $dl->get(10, 20);
foreach($results as $result) {
  // do your thing
}


You can check the apihttp://www.concrete5.org/api/ which is a little hard to navigate but under utilities it shows the methods you can use with DatabaseItemList, also see ItemList etc.