Forum

November 2nd, 2014
A A A
Avatar

Lost password?
Advanced Search

— Forum Scope —




— Match —





— Forum Options —





Minimum search word length is 3 characters - maximum search word length is 84 characters

The forums are currently locked and only available for read only access
sp_Feed Topic RSS sp_TopicIcon
Adding Row Dynamically
30/12/2009
07:56
Avatar
neolivz
Bangalore
Member
Members
Forum Posts: 6
Member Since:
30/09/2009
sp_UserOfflineSmall Offline

Hi,

   I am dynamically adding rows to the grid using addData method. My requirement needs to add a checkbox in the row.

function addRow() {
                var checkBox = "<div style=\\"alignl:center;padding-left:40%;\\"><input type=\\"checkbox\\" name = \\"name[" + count + "].id\\" value=\\"true\\" /></div>";
                var value = "<input type=\\"hidden\\" name = \\"name[" + count + "].value\\" value=\\"" + id + "\\"/>"
                ret['e'] = checkBox + value;
                ret['a']='a';
                ret['b']='b';
                ret['c']='c';
                ret['d']='d';
                selectedNodes.push(id);
                jQuery("#myTable").addRowData(count, ret);
                count++;

    }

I call this method multiple times. It works fine in firefox. But in IE it adds checkbox only in first row.

I have checked the source code of grid.base.js

addRowData : function(rowid,data,pos,src) {

method there is a part

if(t.rows.length === 0){
                    $("table:first",t.grid.bDiv).append(row);
                } else {
                switch (pos) {
                    case 'last':
                        $(t.rows[t.rows.length-1]).after(row);
                        break;
                    case 'first':
                        $(t.rows[0]).before(row);
                        break;
                    case 'after':
                        sind = t.rows.namedItem(src);
                        sind != null ? $(t.rows[sind.rowIndex+1]).hasClass("ui-subgrid") ? $(t.rows[sind.rowIndex+1]).after(row) : $(sind).after(row) : "";
                        break;
                    case 'before':
                        sind = t.rows.namedItem(src);
                        if(sind != null) {$(sind).before(row); sind=sind.rowIndex;};
                        break;
                }

the

$("table:first",t.grid.bDiv).append(row);

works fine but

$(t.rows[t.rows.length-1]).after(row);

does not work fine in IE.

I do not know its know its a bug or not, but it behaves diffrent in diffrent browser.

Here is the complete source code.

<html>
    <head>
        <title>Dojo Test Page</title>
       

        <link rel="stylesheet" type="text/css" media="screen" href="css/theme/official/common.css"/>
        <link rel="stylesheet" type="text/css" media="screen"
              href="scripts/vendor/jquery-ui/css/cupertino/jquery-ui-1.7.2.custom.css"/>
        <link rel="stylesheet" type="text/css" media="screen" href="scripts/vendor/jquery-ui/jqGrid/css/ui.jqgrid.css"/>
       
    <link rel="stylesheet" type="text/css" media="screen" href="scripts/vendor/jqGrid/css/jquery-ui-1.7.2.custom.css" />
    <link rel="stylesheet" type="text/css" media="screen" href="scripts/vendor/jqGrid/css/ui.jqgrid.css" />
    <link rel="stylesheet" type="text/css" media="screen" href="scripts/vendor/jqGrid/css/jquery.searchFilter.css" />
<script src="scripts/vendor/jquery-ui/development-bundle/jquery-1.3.2.js" type="text/javascript"></script>
<script src="scripts/vendor/jquery-ui/development-bundle/ui/jquery-ui-1.7.2.custom.js" type="text/javascript"></script>
<script src="scripts/vendor/jquery-ui/jqGrid/js/i18n/grid.locale-en.js" type="text/javascript"></script>
<script src="scripts/vendor/jquery-ui/jqGrid/src/grid.base.js" type="text/javascript"></script>
<script src="scripts/vendor/jquery-ui/jqGrid/src/grid.custom.js" type="text/javascript"></script>
<script type="text/javascript">
    var count = 0;
    var selectedNodes = new Array();
    var ret = {};
    var id=0;
    jQuery(document).ready(function() {
        jQuery("#myTable").jqGrid({
            datatype: 'local',
            mtype: 'GET',
            colNames:['A','B','C','D','E'],
            colModel:[
                {name:'a',label:'A', editable: false,search:true},
                {name:'b',label:'B', editable: false,search:true},
                {name:'c',label:'C',  align:"center", editable: false,search:true},
                {name:'d',label:'D',  editable: false,search:true},
                {name:'e',label:'E',  editable: true,search:true},
            ],
            height:'191px',
            imgpath: 'css/smoothness/images',
            sortname: 'a',
            sortorder: 'desc',
            enableSearch: true,
            autosearch:true,
            viewrecords: true,
            autowidth:true,
            scroll:false,
            caption: 'Test Page'
        });
        addRow();
        addRow();
        addRow();
    });

  

    function addRow() {
                var checkBox = "<div style=\\"alignl:center;padding-left:40%;\\"><input type=\\"checkbox\\" name = \\"name[" + count + "].id\\" value=\\"true\\" /></div>";
                var value = "<input type=\\"hidden\\" name = \\"name[" + count + "].value\\" value=\\"" + id + "\\"/>"
                ret['e'] = checkBox + value;
                ret['a']='a';
                ret['b']='b';
                ret['c']='c';
                ret['d']='d';
                selectedNodes.push(id);
                jQuery("#myTable").addRowData(count, ret);
                count++;

    }
</script>

    <link rel="stylesheet" href="css/blueprint/grid.css" type="text/css" />
    <link rel="stylesheet" href="css/Simpl.css" type="text/css" />
    <link rel="stylesheet" href="css/twmsWidget/Search.css" type="text/css" />

    </head>
<body>
<div style="padding-top:5px;">
    <table id="myTable" style="width:96%" class="scroll"></table>
</div>
</body>

 </html>

I was able to work around using custom formatter

function checkboxFormatter(el, cval, opts) {
  
        return '<input type="checkbox" />';
      }

It works fine in both ie and firefox 🙂

Regards,

Jishnu

30/12/2009
09:13
Avatar
neolivz
Bangalore
Member
Members
Forum Posts: 6
Member Since:
30/09/2009
sp_UserOfflineSmall Offline

Sorry, this was a mistake.

padding-left:40%;

was making the problem

30/12/2009
11:51
Avatar
neolivz
Bangalore
Member
Members
Forum Posts: 6
Member Since:
30/09/2009
sp_UserOfflineSmall Offline

I fixed the problem by adding

width:100%;

atribute.

Forum Timezone: Europe/Sofia

Most Users Ever Online: 715

Currently Online:
83 Guest(s)

Currently Browsing this Page:
1 Guest(s)

Top Posters:

OlegK: 1255

markw65: 179

kobruleht: 144

phicarre: 132

YamilBracho: 124

Renso: 118

Member Stats:

Guest Posters: 447

Members: 11373

Moderators: 2

Admins: 1

Forum Stats:

Groups: 1

Forums: 8

Topics: 10592

Posts: 31289

Newest Members:

, razia, Prankie, psky, praveen neelam, greg.valainis@pa-tech.com

Moderators: tony: 7721, Rumen[Trirand]: 81

Administrators: admin: 66

Comments are closed.
Privacy Policy   Terms and Conditions   Contact Information