0

I am working on creating a table using the Jqgrid example, I am trying to get the values of all the checked rows and pass the selected values to server using ajax.

Currently it not getting the selected values, when I click get selected button .

here the link to my fiddle

also, is it possible to add radio button to each rows and only one radio button can be selected in the entire table.

  /***********************/
  $("#getSelected").click(function() {
    var ids = $("#output").jqGrid('getGridParam', 'selarrrow');
    if (ids.length > 0) {
      var names = [];
      for (var i = 0, il = ids.length; i < il; i++) {
        var name = $("#output").jqGrid('getCell', ids[i], 'Symbol');
        names.push(name);
      }
      //alert ("Names: " + names.join(", ") + "; ids: " + ids.join(", "));
      $("#names").html(names.join(", "));
      $("#dialog-confirm").dialog({
        height: 280,
        modal: true,
        buttons: {
          'Cancel': function() {
            $(this).dialog('close');
          },
          'Confirm': function() {
            alert("Confirm");
            //alert ("Names: " + names.join(", ") + "; ids: " + ids.join(", "));
            /*$.ajax({
                type: "POST",
                url:  "/cpsb/unprocessedOrders.do",
                data: { method: "releaseTowics",
                    orderNum: JSON.stringify(ids),
                    names: JSON.stringify(names)
                },
                dataType: "json"
                success: function(msg){
                    alert(msg);
                },
                error: function(res, status, exeption) {
                    alert(res);
                }
            });*/
          }
        }
      });
    }
  });
  /***********************/
user244394
  • 13,168
  • 24
  • 81
  • 138

1 Answers1

1

It seems that you use code from the old demo, which I created for the old answer. The demo uses jQuery UI dialog. Thus to make you demo working with minimal changes you should include jquery-ui.min.js and the div, which will be used as jQuery Dialog, for example,

<div style="display:none;" id="dialog-confirm" title="Confirm">
    <p>Are you sure want send this names:</p><p><span id="names"></span></p>
</div>

The modified demo https://jsfiddle.net/OlegKi/615qovew/112/ works. You can replace jQuery UI to Bootstrap dialog, of cause, if you like.

I replaced additionally free jqGrid 4.13.3 to the current free jqGrid 1.14.0 in the demo. I added autoresizeOnLoad: true option and new resetWidthOrg: true property of autoResizing to make the width of columns be resized proportionally the width of the content (see the issue for more details).

Community
  • 1
  • 1
Oleg
  • 220,925
  • 34
  • 403
  • 798
  • Thank you so much . Is it possible to add also radio button to the rows for the existing table? but only one radio button could be selected in the enitire table. This arise one question how would i then know whihc radio button was selected. Is it possible? – user244394 Feb 28 '17 at 16:22
  • @user244394: Look at [the old demo](http://www.ok-soft-gmbh.com/jqGrid/SimpleLocalGridWidthRadioButton.htm) created for [the answer](http://stackoverflow.com/a/7401729/315935). Is it what you need? One should just use custom formatter to set the radio button with the same `name` attribute for all radio buttons of one grid. The optional code of `beforeSelectRow` force selection of radio button on click on any other column of the same row. – Oleg Feb 28 '17 at 16:28
  • @Oleg- I want to have the radio button on the right side added to the table https://jsfiddle.net/dev2020/615qovew/113/ and the checkbox shoudl also be there and usable. My second question is how would i capture the value of the selected radio button when there are checkboxes. ? – user244394 Feb 28 '17 at 16:37
  • @user244394: I don't understand "capture the value of the selected radio button". Do you want to assign `value` attribute to every radio button? I'm not sure where you see any problem. The demo, which link I send you before, finds the radio button in the row. You can use `jQuery.val` to get the value. In any way the discussion is far from the current question. It's better that you post new question with exact description where you see any implementation problems with adding radio button in some column of jqGrid. – Oleg Feb 28 '17 at 16:44
  • Oleg - Thanks I will post a separate one for the radio buttons – user244394 Feb 28 '17 at 16:55