0

Hi I have responsive UI where I am using a jqGrid. In this, when I open it in full-screen the grid works fine. Now, when I try to resize it, horizontal scrollbar comes. Like this

Like this

Now, I referred the internet there are different solutions for this problem and I tried almost whatever I have got my hand on.

I have tried this link jqGrid horizontal scrollbar But here it hides the last columns

I have checked this also - JQGrid How do I removed the annoying horizontal scrollbar when autowidth = true? (In IE) but this was not my case

I have checked this link also - How to get rid of horizontal scroll bar when not needed And the new one where we are getting rid of scrollbar in chrome jqGrid does not render correctly in Chrome/Chrome Frame

I have considered this also - http://www.trirand.com/blog/?page_id=393/help/horizontal-scrollbar

I have applied following properties -

  shrinkToFit: true,
  autowidth:true

My css properties are

 .ui-jqgrid {
  max-width: 100% !important; width: auto !important;}
  .ui-jqgrid .ui-jqgrid-pager {
  width: auto !important;
  }
  .ui-jqgrid-bdiv {
  overflow-y: scroll !important;
  }

  .ui-jqgrid-view,.ui-jqgrid-hdiv,.ui-jqgrid-bdiv {
  width: auto !important;
  }
  .ui-th-ltr, .ui-jqgrid .ui-jqgrid-htable th.ui-th-ltr {
  text-align:center;
  font-style:normal;
  }
  .ui-th-ltr, .ui-jqgrid .ui-jqgrid-htable th.ui-th-ltr > em {
  font-style: normal;
  }

I have tried this solution also

  .ui-jqgrid .ui-jqgrid-btable
  {
  table-layout:auto;
  }

I have also commented out this-

  .ui-widget :active { outline: none; }

Note: I am using IE 11. I want jqGrid to everytime it should calculate the width when user resize the screen so that there will not be horizontal scrollbar

EDITED : I ma using license jqGrid 4.1.2. Its a free version only.

Also, I am using a function here which resize according to browser window

/* Resize grid on browser window */

 function resizeJqGridWidth(grid_id, div_id, width) {
  var cnt = 0;
  $(window).bind('resize', function () {

  }).trigger('resize');

  }

and I am calling it like

 resizeJqGridWidth(grid_id, "gview_" + grid_id, "90%");

My code :

 var grid_data = data,
  grid = $("#" + grid_id);
grid.jqGrid({
            datatype: "jsonstring",
            datastr: grid_data,
            colNames: scopes.grid_header_column_value,
            colModel: scopes.gridcolumns,
            height: height,
            //gridview: true,          
            loadonce: true,
            viewrecords: is_pager_enable,
            rowList: row_list,
            rowNum: row_number,
            multiSort: true,
            ignoreCase: true,
            grouping: is_group_enable,
            sortorder: sort_order,
            cmTemplate: { autoResizable: true },
            autoresizeOnLoad: true,
            autoResizing: { compact: true, resetWidthOrg: true },
            sortable: false,
            pager: "#" + pager_id,
            treeGrid: true,
            treeGridModel: 'adjacency',
            treedatatype: "local",
            ExpandColumn: 'name',
           // sortname: 'name',          
            jsonReader: {
                repeatitems: false,
                root: function (obj) { return obj; },
                page: function () { return 1; },
                total: function () { return 1; },
                records: function (obj) { return obj.length; },
                expanded_field: "true"
            },
            gridComplete: function () {

                $("#" + grid_id+"count").html($("#" + grid_id).getGridParam('records')+" row(s)");

            },

            loadComplete: function () {
                var ts = this;
                //document.querySelector('#filterbutton').addEventListener('onclick', clickqw);
                if (ts.p.reccount === 0) {
                    $(this).hide();
                    emptyMsgDiv.show();
                } else {
                    $(this).show();
                    emptyMsgDiv.hide();
                }

            }            
        });

Added code for opening popup - Here I used to call a funtion getPopup which is then do necessary thing to load a modal window.

if (formatter == "Link") {

                    var subpopup = grid_row_data[j]._attr.popupid._value;
                    var xmlname = grid_row_data[j]._attr.popxml._value;
                    formatter= 'dynamicLink';
                    formoption= {
                            url: function (cellValue, rowId, rowData) {
                                return '/' + rowId + '?' + $.param({
                                tax: rowData.col_nigo,
                                invdate: rowData.col_klo,
                                closed: rowData.col_phq
                            });
                        },
                        cellValue: function (cellValue, rowId, rowData) {
                            return  '<span class="pointer">' + cellValue + '</span>'; 
                            },
                        onClick: function (rowId, iRow, iCol, cellValue, e) {
                            $("#"+subpopup).css("display", "block");
                            $("#" + popupid).css("opacity", "0.99");
                            $scope.getPopup(rowId, iRow, iCol,gridid ,xmlname,rowId);                      
                        }
                    };
                    cellattr = function (rowId, cellValue, rawObject) {
                        var attribute = ' title="' + rawObject.name;
                        if (rawObject.closed) {
                            attribute += ' (closed)';
                        }
                        return attribute + '"';
                    };
                }
            }
Community
  • 1
  • 1
shv22
  • 680
  • 5
  • 28
  • You can hide the overflow (`overflow-x:hidden;`) and the Scrollbar won't appear but then you won't be able to scroll horizontally. Is this what you want to achieve? – Alvaro Mar 22 '17 at 13:44
  • no I want to make it shrink to width every time I resize – shv22 Mar 22 '17 at 13:46
  • Please write in all questions about jqGrid which version of jqGrid you use (can use) and from which fork ([free jqGrid](https://github.com/free-jqgrid/jqGrid), commercial [Guriddo jqGrid JS](http://guriddo.net/?page_id=103334) or an old jqGrid in version <=4.7). Many of your CSS settings are very suspected. Mostly one don't need any changes in CSS. It's enough to register `$(window).bind("resize", ...` event handler, where one calls `setGridWidth` with new width value. See [the old answer](http://stackoverflow.com/a/25036623/315935) and the demo https://jsfiddle.net/OlegKi/andm1299/26/ – Oleg Mar 22 '17 at 14:10
  • @Oleg I have edited the question – shv22 Mar 22 '17 at 14:21
  • Sorry, but jqGrid 4.1.2 is too old. It's dead since many years. You can use it only with retro versions of jQuery (<1.6) and jQuery UI and so on. I strictly recommend you to upgrade jqGrid 4.1.2 to free jqGrid 4.14.0. Just one example: [The old answer](http://stackoverflow.com/a/10621951/315935), which you referenced in your question, describes the bug in rendering in Chrome. jqGrid 4.1.2 calculate the width of cells in wrong way for Chrome. – Oleg Mar 22 '17 at 14:26
  • @Oleg sorry for asking but whether jquery.jqGrid.src is enough to replace or the whole package needs to change – shv22 Mar 22 '17 at 14:37
  • @shv22: You can easy to test free jqGrid in your old application. You need just 1) temporary remove/comment your customization of jqGrid CSSs (all styles, which you posted in the question) 2) replace the usage of old local `ui.jqgrid.css` to loading it directly from CDN: `https://cdnjs.cloudflare.com/ajax/libs/free-jqgrid/4.14.0/css/ui.jqgrid.min.css` 3) remove/comment `grid.locale-en.js` if you use English locale or load new `grid.locale-XX.js` from CDN too 3) load `jquery.jqgrid.min.js` or `jquery.jqgrid.src.js` from CDN too 4) use jQuery in version 1.7.2 or higher (1.12.4 or 3.2.1,...) – Oleg Mar 22 '17 at 14:42
  • @shv22: See [the wiki](https://github.com/free-jqgrid/jqGrid/wiki/Access-free-jqGrid-from-different-CDNs) for all URLs and see [the page](https://free-jqgrid.github.io/getting-started/index.html) for simple examples of the usage of free jqGrid. – Oleg Mar 22 '17 at 14:43
  • @Oleg thanks...will this be enough to solve my problem or after upgrading also I need to change the code? – shv22 Mar 22 '17 at 14:45
  • @shv22: You don't post any code. Thus I can't be sure. But I suppose that the usage of `$(window).bind("resize", ...` would be enough. You can try free-jqgrid 4.14.0 (you need to change just 3-5 rows of your HTML code and comment some lines) first of all. You can post opened questions after your first tests. – Oleg Mar 22 '17 at 14:50
  • @shv22: After your first tests I'd recommend you to examine the demo https://jsfiddle.net/OlegKi/ejpn9/139/, which I posted for [the issue](https://github.com/free-jqgrid/jqGrid/issues/289). The demo uses autoresizable features oh free jqGrid. If you exactly examine the proportions of the width of columns in the demo https://jsfiddle.net/OlegKi/ejpn9/139/ then you will see that the width of columns be used based on the max width of **content** in the corresponding column and the column header. It's the new feature of free jqGrid, which could be helpful for you. – Oleg Mar 22 '17 at 14:55
  • @shv22: To use the autoresizable feature you can add the options `cmTemplate: { autoResizable: true }, autoresizeOnLoad: true, autoResizing: { compact: true, resetWidthOrg: true }` additionally to `autowidth: true`, which you already use. – Oleg Mar 22 '17 at 15:01
  • @Oleg I have added the code in question also I am now using the new free version of jqgrid and also added new properties that you suggested.I have added the $(window).on("resize", function() {... function on resizing as well as while resizing checked the function is calling but still there is some issue as it not adjusting according to screen width. – shv22 Mar 22 '17 at 15:09
  • @shv22: What problem exactly you have? One can see that you use **TreeGrid** and not just a jqGrid. In any way you use it with **local data** `grid_data`. Thus you can easy create standalone demo (in JSFiddle for example), which demonstrates all the problems, which you have. – Oleg Mar 22 '17 at 15:14
  • @shv22: You can disable `autoresizeOnLoad: true` first of all to have the best performance. After your problems with resizing will be clear you can try to use it back, but I'm not sure that the options will work good in case of TreeGrid, because the current implementation don't test *hidden* rows, which could exist in TreeGrid scenario. In any way the exact description of your current opened problems is required to be able to help you more. – Oleg Mar 22 '17 at 15:38
  • @Oleg I will now first make a standalone demo and then I will know where the actual problem is – shv22 Mar 22 '17 at 15:40
  • @Oleg hi I tried to make a standalone and used all the new code which you said it was working but there was one problem I was using a dynamic link in a tree grid (I am using multiple grids) which was not working...so I saw your another example here http://www.ok-soft-gmbh.com/jqGrid/DynamicLink.htm and I used those library so here link came but the responsive was destroyed again...how can I achieve both – shv22 Mar 23 '17 at 10:54
  • You don't need to use dynamic link in free jqGrid because the most properties of `formatter: "showlink"` can be defined as callbacks. You can read [the wiki article](https://github.com/free-jqgrid/jqGrid/wiki/improvement-of-formatter:-%22showlink%22) or examine the source code of `formatter: "showlink"` (see [here](https://github.com/free-jqgrid/jqGrid/blob/v4.14.0/js/jquery.fmatter.js#L384-L436)) . You can ask new questions, where you post how exactly you use currently `formatter: "dynamicLink"`, but I'm busy today and in the next days. I'm not sure when I could find time for answering. – Oleg Mar 23 '17 at 11:01
  • I can't guess what you did wrong with making the grid responsive. You even don't described exactly what you do. I posted you above some demos, which you can use. You should just compare your code with the code of working demos. – Oleg Mar 23 '17 at 11:04
  • Grid is now responsive but the problem is now with tree grid which has a formatter as dynamicLink. Can I use dynamicLink and have responsiveness as well? I have added dynamicLink code as well – shv22 Mar 23 '17 at 11:12
  • I posted new question here http://stackoverflow.com/questions/42975091/open-a-modal-window-from-jqgrid – shv22 Mar 23 '17 at 11:53

0 Answers0