displaying jqgrid in mvc3 after clicking on button - asp.net-mvc-3

I'm building a simple mvc3 app using jqgrid.
My form currently calls a function in my controller that searches the database based on what the user has inputted into the textboxes after clicking on a search button.
I want to only display the jqgrid with the information after clicking on the search button.
Any idea on how to do this?
Thanks

You need to pass an additional variable to the controller to check whether you have selected a button or not.
example:
('#grid').jqgrid({
...
url: '/Controller/Action/?additionalvariable = ' + variable,
...
)};
where the value of the variable is true or false depending on whether you have searched or not.

Related

Url Button in Grid

I have a grid that shows a business component data. One field of this table is an Url type. I don't want to show the url as text, i want show only a button that, if pressed, opens the link.
How I can do that?
I found a solution for the problem:
I changed the visible property of the url field to 'false' and added the link to another field of the grid with this code in the 'load' event:
OtherFieldName.LinkTarget= '_BLANK'
OtherFieldName.Link = link(ATT:UrlFieldName)
I hope this can be useful for you.

dynamically populate Gravity Forms without page reload / anchor down to form

I'm using Gravity Forms on my WP site and when a specific link is clicked, I want the page to scroll down to the contact form where a corresponding field will have been dynamically populated.
I have the dynamic population part working, but my problem is that the project in question is one of those long, one page sites… so when the link is clicked the page reloads and brings the user back up to the top, which is quite confusing. If at this point you scroll down to the form you can see the field has been populated correctly, but I'm looking for a way to do this without making the page reload (ajax?) so they are just anchored down to the now populated form.
form embedded in template:
<?php gravity_form(1, false, false, false, '', true); ?>
link to form:
contact us
The order in which the URL parameters are written matters. This structure won't work:
#contact?message=Testing message
But with the ID at the end it should:
?message=Testing message#contact
This post is what lead me to figure this out:
Correct way to pass multiple values for same parameter name in GET request

Ajax Load Div based on URI (Instead of onClick)

I am converting an old web application. In the legacy version, there is a page which displays some default content when the user navigates to it. There is a link within that page which reloads the page but with a querystring showform=yes which causes a form to be displayed instead of the content.
In the old version, the page was like this:
http://site.com/directory.asp - for the main page with the content
http://site.com/directory.asp?showform=yes - called when the user
clicked the button to show the form.
In the new version of the web app, that same page is set up with ajax, in that there is a div which contains the default content when someone visits http://site.com/directory. There is a button, which, when clicked (from within that page), some ajax is invoked which swaps out the content and displays the form. There is no change in the URI/querystring.
Here is my question - In the legacy version of the web app, there are some other pages which link the user directly to the page with the form (http://site.com/directory.asp?showform=yes) e.g. so they don't need to click the button once the arrive at directory.asp.
Is there a what I can mimimc this behavior based on how I have that page set up now e.g. displaying the form via ajax in a div?)
Initially I thought that perhaps ajax can be triggered based on the presence of a querystring or an anchor in the URI e.g. /directory#form but I am not sure if that is possible.
I would prefer a solution that is not dependent on jQuery, but will consider it if there are no other options.
Thanks in advance for looking, and please let me know if I can further clarify.
Thanks,
Gary
yes you can trigger AJAX call on the basis of a boolean variable which you can set through the query string.
The default value for the boolean variable is false which forces the user to click on the button to refresh the form section.
But when the comes back on the same page the query string will set the boolean variable to true whereby the javascript function containing the AJAX code is invoked from your JSP/ASP or HTML.

jqgrid multiple datepickers and autofocus

i think i found a strange bug in jqGrid.
If you click on this link you can see a jqGrid with a pager. If you click on the '+' button you get the add form in which the 2 datepickers work as expected.
If you now click on this link you can see the very same table, and the very same add button. Anyway if you try to set the second date using tha datepicker you will notice that the focus moves back to the first input, opening the first datepicker.
The example does not work because it has the first field (Id) hidden, so the real first field is a datepicker. Moreover, the edit form is modal.
Last, if you click in this link the behaviour is correct even if the first field is a datepicker. The only thing i changed is the modal property (to false, before it was true).
However, i NEED to hide the Id field AND have a modal window, so i have to to get rid of this problem...
Can someone suggest a solution or an hint?
Thanks
PS: notice that if you set modal: false, you still get the black/transparent overlay like if the window is modal BUT it is not! If you click outisde the edit form it will be closed. This is not acceptable for my requirements.
try to set jqModal parameter into false
var editParams = {
modal: true,
jqModal:false,
... //other options you need
}
grid.editGridRow(row_id, editParams);
for more information see answer Oleg's analisys

Retrieving data posted to a jquery dialog

My question is somewhat related to this answer - https://stackoverflow.com/a/3458299/1635958.
I am working on Asp.Net MVC 3.0.
I have Page1 where I have many controls. When I click on a Button1, I want the ability to make a list of json objects (lets say List personList ) and send that list to a Controller action. I want the view to be opened as a dialog.
So I am trying something like
var $dialog = $('<div></div>')
.load("http://localhost:XXXX/Controler1/Action1")
.dialog({
autoOpen: false,
title: "SomeTitle",
width: 500,
height: 300
});
$dialog
.data("personList", personList)
.dialog('open');
Once I do this, I want the ability to deserialize this data at the controller's side and pass it to a view. Is this doable through this approach? Is there a better approach?
Edit
Requirement is something like this ->
1. Page1 will display a grid of book details.
2. There is an Action column for each row, which is a checkbox
3. User can select the rows he is interested in, and click on a button outside the grid for a specific Action.
4. I should be able to collate data about all the books selected, and pass that data onto a jQuery dialog that gets opened.
5. The jQuery dialog should display the collated data to the user and present him with the ability to take some extra actions.
Edit 2
What is the best practice to have modal dialogs in MVC?
I have a view which shows a grid of items. I want to provide the ability of selecting a subset of the rows, clicking a button, and opening a modal dialog with the selected rows for editing the selected rows and doing more actions. What is the best practice to get this done in MVC? When we click the button, if we call a controller, what is the recommended way to pass data to that controller?
I did it this way ->
I created a json object from the first page. Posted it to the controller as an ajax call. The controller renders a view as a result. I capture the response and display it as a jquery UI dialog. Worked for me.

Resources