I have a View (block display) listing node titles of a certain content type displaying the latest 12 published items. It displays underneath all nodes of a specific type.
What I'd like to do is be able to load the next 12 items with AJAX (I know the pager does this but I was hoping to avoid it) and also control the offset based on the node title.
I think the second request can be achieved with the row number in the query but so far I'm having trouble achieving a working script.
you always can call view results from Drupal API:
$results = views_get_view_result('my_view',$display, $args)
and in arguments you can pass start/end number of items, or something else, depends how you sorting your results
Well, instead of that work, how about selecting the mini pager? I'm pretty sure it only shows previous and next links. If it's not the exact display you want to use, you can override theme_views_mini_pager (from views/theme/theme.inc, line 636) to only show what you need.
Related
The scenario is like this: we have a news website, every page display different type of news nodes. We like to set the in this way that, for a single page, no news node should be display more twice. i.e. should not be duplicate.
We are creating paragraphs, which are fetching different type of news nodes based on taxonomies. For a single page, user can add as many paragraph as they want. Each paragraph display nodes with different layout. Paragraph fetching nodes by entity query and views as well.
So question is, how we can restrict nodes, so that if one displaying in one paragraph, it should not display in another paragraph for a single page?
Something like, if we can create a singleton class or static function, so on page load, it create a blank array, and each subsequent call of that function will fill the array and compare with the old list which are already dumped or added. But I am not sure which hook should be used for page load and how to handle the views query.
Beside this should be session specific and also keep it mind about the performance.
Does anyone has any idea on this? Surely its complex.
Ok, so I'm in the process of expanding my knowledge and need a step in the right direction, not necessarily an answer.
I am wanting to create a script for my eCommerce site that lets users choose between grid and list view on product listings pages.
The grid view will be called using an included file called "incgridview.asp" - the list view file is called "inclistview.asp".
Upon the user choosing an option from the drop down specifying which type of view they want, the respective file should be called. So if they select grid view, I need to load the incgridview.asp (list view will be loaded by default).
Once the selection is made, I need it to switch the view without reloading the page, and store a cookie for 7 days that remembers their selection. Of course, they would still have the option to switch back to the other view.
So basically I am switching which file is included upon user selection of the drop down. Im thinking maybe I need to use ajax but not sure. Any help is greatly appreciated. Thanks!
EDIT
Ok, so this is what I am trying to use, on my file that actually includes the grid pages. It is throwing up this error:
Microsoft VBScript runtime error '800a01b6'
Object doesn't support this property or method: '[object]'
/productsviewtest.asp, line 59
Dim listgridcookie
listgridcookie = Response.Cookies("atdviewcookie")("viewoption")
Select Case listgridcookie
Case "list"
print"list view"
Case "grid"
print "grid view"
Case Else
Response.Cookies ("atdviewcookie")("viewoption") = "grid"
Response.Cookies ("atdviewcookie").Expires = DATE + 7
Response.Redirect(Request.RawUrl)
End Select
here is a steps on your page load:
1) Check if cookies exists and what values are there, if it does not exists - create one with default value.
2) Based on value from cookies show div which has been loaded with data from proper include file.
3) When/if selection changes create/re-write cookies with expiration time you desire.
All what you need to build is JavaScript based switch to show one element and hide another.
If you like to use AJAX or JQuery - you can do it this way but for my taste it take away challenges of creating something you can be proud of.
This is based on your " page must not be reloaded upon changing selection" statement.
In drupal I have created a view to display node's title and added exposed filter for filtering content. When the view page is loaded it is returning two nodes, I do not know on what basis it is returning those two nodes. I want no result to be displayed until I select some value in filter. Please suggest?
Views is a query builder that starts with the simplest, broadest possible query, and filters are required to narrow that query to include only the items you wish. If you are familiar with SQL syntax, the default query would look something like this:
SELECT title, body FROM 'node'
This is why you're seeing two nodes when you load the page. There's no filter applied, so it's showing everything.
In order to get your View to only display items once the user has selected a value with the exposed filter, go into the Advanced > Exposed Form > Exposed Form Style and select Input required. I have tested this using Views 7.x-3.7 and I believe it will give you the behaviour you're looking for.
I have a bit of a unique challenge today. I have a client that wants to be able to search for multiple items based on inserts into a cfgrid. Suppose we have the following web form:
A Country selection dropdown
A State Selection dependent AJAX dropdown
A city Selection dependent AJAX dropdown
An ADD Button
----------------------------------------------------
A CFGRID that will populate a row with selections when the user clicks the add button
----------------------------------------------------
And finally, a CLEAR button, and a GO button on the bottom.
The resulting page will then query the database and get some statistics about the cities selected. So, suppose an individual picks USA > Arizona > Scottsdale and USA > Arizona > Flagstaff. The grid below the options will 'save' each selection and reset to their default options, waiting for a user to pick additional options or click on 'GO'.
The resulting page will then generate columns that list some statistics about the communities and highlight the 'best of' between each selected community.
Each time a user selects the ADD button (assuming three criteria are selected) I want the information to be added into a CFGRID that displays the options selected. Then, After the user selects at least one country/city/state option, have all of the data in the CFGRID get passed to another page that does a query from the data selected. In theory, the user could pick as many communities as they want, assuming they are willing to let the database sludge through enough data to get what they want and wait through a 'loading' screen to get it.
I'm having these challenges, in no particular order:
- I have an HTML grid that I must use per client spec (No Java or Flash, must be HTML)
- I have no idea how to get the selected options into the CFGRID. I assume there is some JavaScript I can write that uses some sort of AddRow function to add data into the grid with the add button but cannot seem to find how to it on the interwebs
- After we conquer the above challenge, how do I pass the data from the grid into the results page? I thought about passing one big string or a structure, but I'm not sure how to do that through the URL or posting, nor how to get the data out of the grid. I wonder if I am better off coding some sort of string that gets passed from the options page to the results page with a get method instead of dealing with the stuff in the CFGRID and have the CFGRID serve only as a 'dummy' display container.
- Finally, after the pass is complete, I would need to loop through through the structure and perform a CFQUERY or CFSTOREDPROC on each row of data, then get the statistics I need to display on the results page. I assume this would depend on how I am getting the data from the options selection page to the results page.
THANK YOU ALL!
CFGRID is great to start, but it can be b*tch to customize and extend... Have you tried editable CFGRID with bind? See how far off it is from what you want first. If it turns out to be very far, then you might want to go for a jqGrid and code up some jQuery.
To start, read Using HTML grids and make the cfgrid editable.
http://help.adobe.com/en_US/ColdFusion/9.0/Developing/WSc3ff6d0ea77859461172e0811cbec22c24-7a01.html#WSc3ff6d0ea77859461172e0811cbec22c24-72e0
Once you got that working, look at these provided JS functions that you can use with CFGRID
http://help.adobe.com/en_US/ColdFusion/9.0/CFMLRef/WS0ef8c004658c1089-6262c847120f1a3b244-8000.html
http://help.adobe.com/en_US/ColdFusion/9.0/CFMLRef/WSd160b5fdf5100e8f-4439fdac128193edfd6-7f5f.html
If you still demand a bit more, you might need to dig into the underlying ExtJS component. At that point I would rather use jqGrid
I found out that the best way to handle this was by using a SerializeJSON call and a Deserialize JSON call back and forth. By using JavaScript notation we are able to pass a complex JavaScript object (array) between one page and another. This has the value add of not having to worry about sessions timing out and making URLs clickable from one solution to the next.
I have a request concerning Drupal 6.x
I'd like to have this behaviour:
imagine to have 2 columns, on the left a list of nodes (only titles for example) and on the right a view showing just one of the contents on the left.
My idea would be to achieve this with an AJAX-fashion: clicking a link in the list on the left updates the view on the right with the actual node.
Which is the best way to handle this?
My idea is to use Panels, make 2 column panel with 2 views, one (left) filtered on content type, with no arguments, and one on the right which takes in as an argument the node id to be displayed.
But how to link the 2 views with AJAX?
(or, better, how to update the view on the right with an AJAX call?)
is this possible?
Any help or idea is really welcome
Thanks!
Cheers
Mauro
You also can do a quick hack, which is quite flexible, because it allows you to change your views without changing code.
I have had a similar task recently and for your task I would do the following:
for your right column, create a exposed filter (node id) and hide whole exposed filter form using CSS.
using jQuery, attach a click behavior to titles on your left column.
the click behavior takes the node id, finds the attached exposed filter at the right column, enters the node id into the input field and executes form's .submit().
the .submit() triggers the build-into-views well debugged ajax request which refreshes your right column.
this is certainly possible, and not very difficult to do.
Your task can be divided into two main parts:
Providing a 'callback' URL in the Backend that takes a node id (nid) and returns the markup to display the node in the right panel in a format that can be processed by javascript. This will be done in PHP within a normal Drupal module. The main point is not to return a full Drupal page as usual, but only the markup for the node.
Create logic for the Frontend that, when triggered by clicking a link in the left panel, retrieves the new node markup via the URL callback above and replaces the content of the right panel with it. This needs to be done in javascript, using the Drupal javascript API with jQuery.
You can find an introduction and example for AJAX in Drupal here. (This does almost exactly what you want to do, only with images)
You should also look at this more general entry point for JavaScript in Drupal.