Tuesday, May 28, 2024
 Popular · Latest · Hot · Upcoming
25
rated 0 times [  27] [ 2]  / answers: 1 / hits: 38424  / 15 Years ago, mon, july 20, 2009, 12:00:00

I have the following jQuery code which I'm using to populate a jqGrid. It works perfectly posting to my ASP.NET MVC page on the first click of the button. My

problem is, any other clicks past the first it seems to run through the jquery code when clicking the button but it never makes it to the POST page. Any ideas why?



<script type=text/javascript>

$(document).ready(function() {
$('#btnSubmit').click(function() {

/* Refreshes the grid */
$(#list).jqGrid({
/* The controller action to get the grid data from */
url: '/CRA/AddPart',
data: { partNumber: 123},
datatype: 'json',
mtype: 'GET',
/* Define the headers on the grid */
colNames: ['col1', 'col2', 'col3', 'col4'],
/* Define what fields the row columns come from */
colModel: [
{ name: 'col1', index: 'invid', width: 290 },
{ name: 'col2', index: 'invdate', width: 290 },
{ name: 'col3', index: 'amount', width: 290, align: 'right' },
{ name: 'col4', index: 'tax', width: 290, align: 'right'}],
height: 'auto',
rowNum: 10,
rowList: [10, 20, 30],
sortname: 'id',
sortorder: desc,
viewrecords: true,
imgpath: '../../Scripts/jgrid/themes/steel/images',
caption: 'Core Return Authorization Contents:',
cellEdit: true
});
});
});

</script>

More From » jquery

 Answers
17

The reason the grid isn't reloading is that you are calling the wrong method. The jqGrid method does approximately this:




  1. Examine the table to see if it is already a grid; if so, exit.

  2. Turn the table into a grid.

  3. Populate the first page of data.



So the second time you call the method, it does nothing, as per step 1.



Instead, you should be calling $(#list).trigger(reloadGrid) on the second and all subsequent clicks.



Now, because of your mtype in the grid options, the grid is going to do a GET, not a POST. So if the POST is coming from the button itself (in other words, it is an input of type submit), you should return true to indicate that the submit should continue as usual.


[#99093] Wednesday, July 15, 2009, 15 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
deanna

Total Points: 84
Total Questions: 86
Total Answers: 107

Location: Cyprus
Member since Wed, Dec 8, 2021
3 Years ago
;