Skip to content

checkbox in grid

New Discussion
William Morgenweck
William Morgenweck asked on Mar 10, 2015 6:56 AM

What I would like to end up with is a simple grid that cannot be edited but with a simple checkbox in the first row.  This checkbox will be able to be checked and unchecked with the mouse.  All checkboxes will be check when loaded.  When the process is complete and the end user has uncheck the boxes that he or she wants then I want to loop through the grid and read the values of the second column based upon the value of the check mark.  The data that I’m using is being pulled from a web service writing JSON from a MS SQL database.  What the best way to do this?

Sign In to post a reply

Replies

  • 0
    Zdravko Kolev
    Zdravko Kolev answered on Oct 29, 2014 12:56 PM

    Hello William,

    Thank you for contacting us.

    I hope that I understand correctly your requirements, if not please let me know what I am missing from your scenario. Below you can find a sample where I have a grid with template column which have checkboxes, and when I press a button I am getting the value from ProductNumber field and I am showing it in alert box. You should use a similar approach.

    1. <script type=”text/javascript”>
    2.         function getInfo() {
    3.             var $grid = $(“#grid1”);
    4.             var rowsLength = $grid.igGrid(“allRows”).length;
    5.             for (var i = 0; i < rowsLength; i++) {
    6.                 var cell = $grid.igGrid(“cellAt”, 0, i)
    7.                 var $checkBox = $(cell.children[0]);
    8.                 if ($checkBox.prop(“checked”)) {
    9.                     alert(“ProductNumber” + $grid.igGrid(“getCellValue”, i, “ProductNumber”));
    10.                 }
    11.             }
    12.         }
    13.         function changeState(element, rowId) {
    14.             var $checkBox = $(element);
    15.             if ($checkBox.prop(“checked”)) {
    16.                 $checkBox.attr(‘checked’, ‘checked’);
    17.             } else {
    18.                 $checkBox.removeAttr(‘checked’);
    19.             }
    20.         }
    21.     </script>
    22.     <script type=”text/javascript”>
    23.         var products = [
    24.             { “id”: 1, “Checked”: true, “ProductNumber”: “0” },
    25.             { “id”: 2, “Checked”: true, “ProductNumber”: “1” },
    26.             { “id”: 3, “Checked”: true, “ProductNumber”: “2” }
    27.         ];
    28.         var mytemplate = “<input type=’checkbox’ {{if ${Checked} }} checked {{/if}} onclick=’changeState(this, ${id})’ />”;
    29.         $(function () {
    30.             $(‘#grid1’).igGrid({
    31.                 autoGenerateColumns: false,
    32.                 //renderCheckboxes: true,
    33.                 autoCommit: true,
    34.                 width: ‘500px’,
    35.                 columns: [
    36.                    { headerText: “Checked”, key: “Checked”, dataType: “bool”, template: mytemplate },
    37.                    { headerText: “Id”, key: “id”, dataType: “number” },
    38.                    { headerText: “ProductNumber”, key: “ProductNumber”, dataType: “string” },
    39.                 ],
    40.                 dataSource: products
    41.             });
    42.         });
    43.     </script>

    Looking forward to hearing from you.

     

    Checkboxes

    • 0
      William Morgenweck
      William Morgenweck answered on Oct 30, 2014 1:21 PM

      This is perfect.

      Thank you–

    • 0
      Al Maiz
      Al Maiz answered on Mar 5, 2015 3:17 PM

      hey Zdravko, i have a simliar question. i have a grid with a checkbox column (checkbox header to select all). when i click the checkboxes or the header checkbox i want to display count of total items checked in a seperate label. 

      i have it working for checking each individual checkbox but not the check all. 

      p.s. not using template column

      how would i go about that?

      thanks

      • 0
        Zdravko Kolev
        Zdravko Kolev answered on Mar 10, 2015 6:56 AM

        Hello Al,

        Clicking on the header checkbox will check/uncheck all checkboxes, so my suggestion is to implement this functionality somewhere else.

        In order to count the checkboxes you can iterate through all rows and use 'is' in order to check if the checkbox for the particular row is checked:

        http://stackoverflow.com/questions/901712/check-checkbox-checked-property

  • You must be logged in to reply to this topic.
Discussion created by
Favorites
Replies
Created On
Last Post
Discussion created by
William Morgenweck
Favorites
0
Replies
4
Created On
Mar 10, 2015
Last Post
11 years, 7 months ago

Suggested Discussions

Created by

Created on

Mar 10, 2015 6:56 AM

Last activity on

Feb 23, 2026 3:47 PM