views:

272

answers:

3

I have a master grid and want to display the results on row click from master grid in detail grid.. I am not able to fetch the data on my detail grid ....

  $(document).ready(function(){
      { $("#navmenu-v li").hover( 
                    function() {
                        $(this).addClass("iehover"); }, 
                    function() { 
                        $(this).removeClass("iehover");
            } );

      jQuery("#list10").jqGrid({
                 sortable:true,
             url: '/cpsb/json/jsonpageheader.txt',
             datatype:'json',
             colNames:['Order','Load', 'Gate Time', 'Stop','Customer','Status'], 
             colModel:[  
                         {
                                name:'orderNumber',
                                index:'orderNumber',
                                width:130,
                                align:"center",
                                sorttype:"int"

                         },
                         {
                                name:'loadNumber',
                                index:'loadNumber', 
                                width:100, align:"center",
                                sorttype:"int"


                         },
                         {
                                 name:'latestTime',
                                 index:'latestTime', 
                                 width:160,
                                 align:"center"

                          }, 
                         {
                                     name:'stopSeq',
                                     index:'stopSeq',
                                     width:80, 
                                     align:"center", 
                                     sorttype:"int"

                        },
                         {
                                     name:'customerNumber',
                                     index:'customerNumber', 
                                     width:100,align:"center", 
                                     sorttype:"int"

                        },
                         {
                                     name:'orderStatus',
                                     index:'orderStatus', 
                                     width:80, align:"center"

                         } ],

           rowNum:10,
           rowList:[10,20,30],
           jsonReader : {repeatitems: false,
            root: function(obj) {
                return obj;
            },
            page: function (obj) { return 1; },
            total: function (obj) { return 1; },
            records: function (obj) { return obj.length; }
        },
           pager: '#pager10',
           sortname: 'Gate Time',
           sortorder: "desc",
           viewrecords: true,
           multiselect: true,
           caption: "Order Header",


           onSelectRow: function(ids) {
                 if(ids == null) {
                      ids=0; 
                      if(jQuery("#list10_d").jqGrid('getGridParam','records') >0 )
                           { 
                            jQuery("#list10_d").jqGrid('setGridParam',{url:"/cpsb/unprocessedOrders.do?method=getUnprocessedOrderDetails"+ids,page:1});
                            jQuery("#list10_d").jqGrid('setCaption',"Order Header: "+ids).trigger('reloadGrid'); } 
                           }
                          else { 
                              jQuery("#list10_d").jqGrid('setGridParam',{url:"/cpsb/unprocessedOrders.do?method=getUnprocessedOrderDetails"+ids,page:1});
                               jQuery("#list10_d").jqGrid('setCaption',"Order Details: "+ids).trigger('reloadGrid');
                                }
                         } ,
                         height:'100%'
         }); 
          jQuery("#list10").jqGrid('navGrid','#pager10',{excel:true, add:false,edit:false,del:false,searchtext:"Filter"},{},{},{},{multipleSearch:true});
         $("#list10").jqGrid('hideCol', 'cb');


         jQuery("#relCasePick").click( function(){
             var id = jQuery("#list10").jqGrid('getGridParam','selarrrow');
             alert(id);

              }); 


          jQuery("#list10_d").jqGrid({ 
              height: 100, 
              url:'/cpsb/unprocessedOrders.do?method=getUnprocessedOrderDetails',
              datatype: "json",
              colNames:['Order','SKU', 'UPC', 'Item Description','Quantity Ordered','Teach in Hold?'],
              colModel:[ {name:'Order',index:'', width:55},
                         {name:'SKU',index:'sku', width:55},
                         {name:'UPC',index:'qty', width:40, align:"right"},
                         {name:'Item Description',index:'unit', width:150, align:"right"}, 
                         {name:'Quantity Ordered',index:'quantity', width:150,align:"right", sortable:false, search:false},
                         {name:'Teach in Hold?',index:'teachInId', width:150, align:"right"},  ],
              rowNum:5,
              rowList:[5,10,20],
              jsonReader : {repeatitems: false,
                    root: function(obj) {
                        return obj;
                    },
                    page: function (obj) { return 1; },
                    total: function (obj) { return 1; },
                    records: function (obj) { return obj.length; }
                },
              pager: '#pager10_d',
              sortname: 'SKU',
              viewrecords: true,
              sortorder: "asc",
              multiselect: true,
              caption:"Order Detail" 
             }).navGrid('#pager10_d',{add:false,edit:false,del:false}, {},{},{},{multipleSearch:true});
              jQuery("#ms1").click( function() {
              var s; 
              s = jQuery("#list10_d").jqGrid('getGridParam','selarrrow'); 
              alert(s); }); 
      }});

is there a way that i will not pull the other grid data and instead of that only on row click from 1st grid i will get the values for next grid

A: 

In your current code you set url for the detail grid like

"/cpsb/unprocessedOrders.do?method=getUnprocessedOrderDetails"+ids

do you want probably have

"/cpsb/unprocessedOrders.do?method=getUnprocessedOrderDetails&someParameter="+ids

Could you also reformulate your second question

is there a way that i will not pull the other grid data and instead of that only on row click from 1st grid i will get the values for next grid?

What do you mean under "to get the values for next grid"? Is next grid is detail grid? From where you want to get the values? With respect of getRowData method (see http://www.trirand.com/jqgridwiki/doku.php?id=wiki:methods#grid_related_methods) you can get full data from the selected row of the master grid, but from which source you plan to get data for the detail grid?

Oleg
jQuery("#relCasePick").click( function(){ var rows= jQuery("#list10").jqGrid('getRowData'); var paras=new Array(); for(var i=0;i<rows.length;i++){ var row=rows[i]; paras.push($.param(row)); } $.ajax({ type: "POST", url: "/cpsb/unprocessedOrders.do?method=releaseToCasePick", data: paras.join('and'), success: function(msg){ alert(msg); } });can i do like this
Paul
Yes. Something like that can work. I would only call `jqGrid('getGridParam','selarrrow')` to get ids only selected rows and not call `jqGrid('getRowData')` without the second parameter, which get **all data** from the grid. Moreover if you need only values from the `orderNumber`, you can use `jqGrid('getCell', ids[i], 'orderNumber')` instead of `jqGrid('getRowData', ids[i]).orderNumber`. If the values from `orderNumber` are unique you can use this column as id. To do this insert 'key: true' in the column definition of `orderNumber` column.Then ids from `selarrrow` will be values which you need
Oleg
How to pack the data which you want to send to the server you should decide yourself. In general if `ids` is an array of IDs which you want to send, then `JSON.stringify` will be JSON formated string with the data. You can use `$.ajax({ type: "POST", url:someUrl, data: JSON.stringify(ids), dataType: "json", success: function(msg) {alert(msg);}});` to send the data. Depend on you server components which you use if cen be required to change `data:JSON.stringify(ids)` to something like `data:{myParam: JSON.stringify(ids)}`. Then you will be able to get input data from `myParam` input parameter.
Oleg
but when I am trying to use jqGrid('getGridParam','selarrrow') it is not iterating through the selected records ...and using this now not allowing me to select multiple records...what I am doing wrong ?
Paul
Sorry I not exactly understand you problem. If some rows in multiselect grid are selected, then `var ar = jqGrid('getGridParam','selarrrow');` returns array of selected ids. To iterate through elements of an array you can use standard "for" loop where `ar[i]` is i-th selected element. You should take in consideration that javascript type if `ar[i]` is string and not number.
Oleg
you should also read http://stackoverflow.com/faq#howtoask and consider to mark the answers which **really** solve the problem from your question as *accepted* and *vote* some answers which where helpful (or do both accepting and voting). It will help other people to see **solved problems** and also **helpful answers**.
Oleg
A: 

Yes next grid is detail grid... what is basically do is to fetch the corresponding values for order number from master grid and display it in detail ....

for second part

is there a way that i will not pull the other grid data and instead of that only on row click from 1st grid i will get the values for next grid?

Instead of getting all the data from server can I just pull the data only on selecting the row from first grid...

Moreover, I have a button call release to case pick and clicking on that button I have send the selected rows to database....I hav ea action class for that but how I have to send that selected rows.

jQuery("#relCasePick").click( function(){
             var id = jQuery("#list10").jqGrid('getGridParam','selarrrow');
             alert(id);

              });

can i do something like jQuery(("#list10").jqGrid('getGridParam','action class URL')

Paul
A: 

can I do something like this for sending the rows to server

jQuery("#relCasePick").click( function(){
             var rows= jQuery("#list10").jqGrid('getRowData');
              var paras=new Array();
              for(var i=0;i<rows.length;i++){
                  var row=rows[i];
                  paras.push($.param(row));
              }
              $.ajax({
                  type: "POST",
                  url: "/cpsb/unprocessedOrders.do?method=releaseToCasePick",
                  data: paras.join('and'),
                  success: function(msg){
                      alert(msg);
                  }
              });
Paul
One more advice. It is better if you need post additional information about your question you append you question with the words **UPDATED**, **UPDATED 2**, **Edited** and so on and then append the original text of the question with new information. It will make other people easy to find the information.
Oleg