0

I am using column chooser for customizing columns in jqGrid records, but iam appending <thead> to jqGrid for alignment purpose, for this iam unable to reorder my jqGrid columns with columnChooser.

My code is:

if (success==true) {    
    $("#merror").text('');

    $("#list1").jqGrid("GridUnload")
    $("#list1").jqGrid({
        url:"./controllers/apGetTestData.php?testanzres=1&testsuite="+testsuite+
            "&testcase="+testcase+"&ch="+ch+"&fromdate="+fromdate+
            "&todate="+todate+"&mmss="+mmss,
        datatype: 'xml',
        mtype: 'GET',
        height: 'auto',
        colNames:[ 'RRID', 'Release Tag','Completed Date','Result', 'Firm  Ware','DUT','Summary','Remarks'],
        colModel:[
            {name:'idreleaseRequest', index:'idreleaseRequest', width:24},
            {name:'releaseRequestTag', index:'releaseRequestTag'},   
            {name:'DateInfo', index:'Date Info', sortable:false,align:'center'},
            {name:'Result', index:'Result', sortable:false},
            {name:'Firm Ware', index:'Firm Ware', sortable:false},
            {name:'DUT', index:'DUT', sortable:false},              
            {name:'Summary', index:'Summary', sortable:false, align:'left'} ,
            {name:'Remarks', index:'Total Suites', sortable:false}],       
        pager: $('#pager1'),
        rowNum:6,
        rowList:[6,12,18,24],
        sortable:true,
        sortname: 'timeStamp',
        sortorder: "DESC",
        // caption:"Test Results : "+ globalData,
        caption:"Test Results ",
        shrinkToFit:true,
        autowidth: true,
        viewrecords: true,
        rownumbers:true,
        cloneToTop:true, 
        hidedlg: true        
    });
    $("table.ui-jqgrid-htable thead").appendTo("table#list1");
    function  ShowHideColumn () {
        $.extend(true, $.ui.multiselect, {
            locale: {
                addAll: 'Make all visible',
                removeAll: 'Hide All',
                itemsCount: 'Avlialble Columns'
            }
        });
        $.extend(true, $.jgrid.col, {
            width: 450,
            modal: true,
            msel_opts: {dividerLocation: 0.5},
            dialog_opts: {
                minWidth: 470,
                show: 'blind',
                hide: 'explode'
            }
        });
        $("#list1").jqGrid("setColProp", "rn", {hidedlg: false});
        $('#list1').jqGrid('columnChooser');

when i am re-odering columns through column chooser thead names are not reordering but values are reorder, how to solve this problem would anyone help me on this please, thanks

enter image description here

and i am using this js files

  <script type="text/javascript" src="../js/jquery.js"></script>
    <script type="text/javascript" src="../js/jquery-ui.js"></script>
    <script type="text/javascript" src="../js/popup/popup.js"></script>
    <script type="text/javascript" src="js/viewTestReq.js"></script>   
     <script type="text/javascript" src="../js/jquery.validate/jquery-validate.js"></script>
    <script type="text/javascript" src="../js/jquery.form/jquery.form.js"></script>
    <script type="text/javascript" src="http://code.jquery.com/jquery-1.7.1.min.js"></script>
    <script type="text/javascript" language="javascript" src="http://code.jquery.com/jquery-ui- 1.8.2.custom.min.js"></script>
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.18/jquery-ui.min.js"></script>
    <script type="text/javascript" src="../js/ui.multiselect.js"></script>         
    <script type="text/javascript" src="../js/jqGrid/js/i18n/grid.locale-en.js"></script>        
    <script type="text/javascript" src="http://www.ok-soft-gmbh.com/jqGrid/jquery.jqGrid-4.3.1/js/jquery.jqGrid.min.js"></script>
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.18/jquery-ui.min.js"></script>

For column Chooser i am using seperate function like this:

    function  ShowHideColumn () {
            $.extend(true, $.ui.multiselect, {
            locale: {
                addAll: 'Make all visible',
                removeAll: 'Hide All',
                itemsCount: 'Avlialble Columns'
            }
        });
        $.extend(true, $.jgrid.col, {
            width: 450,
            modal: true,
            msel_opts: {dividerLocation: 0.5},
            dialog_opts: {
                minWidth: 470,
                show: 'blind',
                hide: 'explode'
            }
        });
      $("#list1").jqGrid("setColProp", "rn", {hidedlg: false});
     $('#list1').jqGrid('columnChooser');


 }
Sravya
  • 27
  • 11
  • The line `$("table.ui-jqgrid-htable thead").appendTo("table#list1")` seems be wrong. Why you do this? It beak internal structure of jqGrid. What is your goal? By the way I would recommend you to use `postData` with functions instead of building `url` like you do currently (see [the answer](http://stackoverflow.com/a/2928819/315935) for details). – Oleg Sep 15 '14 at 05:01
  • Hi Oleg, i really mean on what you said, if i am not adding that line jqgrid columns alignment is not appearing good, that's the case i am appending that line, i have large data to display in one column, is there any solution to reorder columns without removing this line or else tell me any other solution which alignment should be perfect for large data , and reoder of columns. Please help me on this and thanks for your reply. – Sravya Sep 15 '14 at 05:11
  • Hi Oleg, I used PostData but there is no use, i am unable to solve this issue till one week, i am stucked at this, please help me on this, thanks – Sravya Sep 15 '14 at 05:19
  • You should describe more detailed *your original problem*. What you mean under "columns alignment"? Alignment of column headers or cells of grid? Vertical or horizontal alignment? etc See [the answer](http://stackoverflow.com/a/3006853/315935) about alignment of column headers. – Oleg Sep 15 '14 at 05:24
  • I write about `postData` because requests to `url` will be because of some *internal* actions of jqGrid. If the values `testsuite, testcase, ch, fromdate, todate, mmss` of the URL come from some controls on your page then you will see that on paging or sorting of jqGrid could be sent *old* values. Additionally you could require to use `encodeURIComponent` during building URL manually. – Oleg Sep 15 '14 at 05:31
  • Hi Oleg, I want help about column headers, when i am using column chooser reorder columns column header names are not ordering in correct format what it is showing in column chooser dialog form, and about alignment: the cell value width is 480px approx , it is not constant,it is changing based on the value , but column header column name width is not changing based on the values width, that's why i appended that line, i am unable to post the iamge overhere otherwise i'll clearly show my problem through iamge – Sravya Sep 15 '14 at 05:34
  • Hi oleg, or else could you tell me how to set column header names width, based on the values width which are displayed below the column header, i hope you understand my problem – Sravya Sep 15 '14 at 05:42
  • Sorry, I don't understand your question. The width of column header is always **the same** as the width of column headers in the grid body (of cause if you don't break internal structure of jqGrid by moving column headers to another location). – Oleg Sep 15 '14 at 05:57
  • Hi oleg, please view this link [link]http://tinypic.com/view.php?pic=6ekg78&s=8#.VBaDlfmSyaI, you'll get to know what problem i am facing, i don't know where to post the image i posted here so please look into this and help me, click on that image for larger view please – Sravya Sep 15 '14 at 06:15
  • Hi oleg, if you seen that image you'll get to know what problem i am facing, please reply me – Sravya Sep 15 '14 at 06:45
  • The problem is in the code which produce the picture. The code `$("table.ui-jqgrid-htable thead").appendTo("table#list1");` is not solution. **Do you have the demo which reproduces the problem?** I suppose that it's problem in how you use jqGrid. It's not common problem of jqGrid. – Oleg Sep 15 '14 at 06:48
  • we run through server, i don't know where to post the code or demo, and i posted the image after removing that code. – Sravya Sep 15 '14 at 06:58
  • http://jsfiddle.net/ allows you to post the code for example. One can replace the `datatype` to `"local"` with the data as values of the `data` parameter. Alternatively you can use `/echo/json` urls. – Oleg Sep 15 '14 at 07:01
  • Hi Oleg, i added some sample data to show you,[link]http://jsfiddle.net/y2yfuvjy/1/, $("table.ui-jqgrid-htable thead").appendTo("table#list1"); i added this code and another [link]http://jsfiddle.net/y2yfuvjy/ by removing that code you please reply me by seeing this thank you – Sravya Sep 15 '14 at 08:41
  • I hope you'll understand my problem while seeing that links, for first link i has to reorder column names correclty, for second link i has to set correct width for column names based on below displayed values – Sravya Sep 15 '14 at 08:43

1 Answers1

0

You included multiple times jQuery and jQuery UI and even in different versions. It's wrong! See

<script type="text/javascript" src="../js/jquery.js"></script>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.7.1.min.js"></script>

and

<script type="text/javascript" src="../js/jquery-ui.js"></script>
<script type="text/javascript" language="javascript" 
        src="http://code.jquery.com/jquery-ui-1.8.2.custom.min.js"></script>
<script type="text/javascript"
        src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.18/jquery-ui.min.js"></script>
<script type="text/javascript"
        src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.18/jquery-ui.min.js"></script>

One should include every JavaScript library only ones!!!

Additionally I don't recommend you to use old 4.3.1 version of jqGrid and include copy of jqGrid from my web site (http://www.ok-soft-gmbh.com/jqGrid). There are some public CDN (Content Delivery Network) with jqGrid. For example cdnjs (see here) or jsdelivr (see here):

<link rel="stylesheet" type="text/css"
      href="http://cdnjs.cloudflare.com/ajax/libs/jqgrid/4.6.0/css/ui.jqgrid.css"/>
<script type="text/javascript" 
        src="http://cdnjs.cloudflare.com/ajax/libs/jqgrid/4.6.0/js/i18n/grid.locale-en.js"></script>
<script type="text/javascript"
        src="http://cdnjs.cloudflare.com/ajax/libs/jqgrid/4.6.0/js/jquery.jqGrid.min.js"></script>

UPDATED The jsfiddle demo which you posted contains a lot of unneeded CSS rules which is origin of the problem with wrong alignment of the columns. The fixed demo http://jsfiddle.net/OlegKi/y2yfuvjy/2/ don't have the problem.

UPDATED 2: One can't just set table-layout:auto for all internal tables of jqGrid. It will break internal structure of jqGrid. If you need to set the width of columns based on the width of content on cells in the column or column header then you can follow the demo which I created for the answer. See http://jsfiddle.net/OlegKi/y2yfuvjy/7/.

Community
  • 1
  • 1
Oleg
  • 220,925
  • 34
  • 403
  • 798
  • Hi oleg, thanks for your help, i really irritated you, i am knowing that, but again i got a problem after using column chooser it's not setting column width, it is displaying basic column width – Sravya Sep 15 '14 at 10:58
  • @Sravya: Of cause you can't change the width of the column is you the width will be set based on the content of the cells in the column. If you need to change the width of the column you have to change the content in the column. You can still use Column Chooser to hiding/showing columns or for changing the order of columns. – Oleg Sep 15 '14 at 11:06
  • Actually i am using column chooser seperately, i posted the code above, after that how to set column width which is displaying before columnchooser option – Sravya Sep 15 '14 at 11:11
  • @Sravya: If I correctly understand your problem you need just change from binding to "jqGridAfterLoadComplete" to binding to 2 events "jqGridAfterLoadComplete jqGridRemapColumns": see http://jsfiddle.net/OlegKi/y2yfuvjy/7/ – Oleg Sep 15 '14 at 11:42
  • Hi Oleg, i am getting a problem, the grid width is not setting to page size,shrinkToFit:false,$("#list1").setGridWidth($(window).width()) ; if i am using this code i am getting scroll bar, could you help me that how to set grid to browser page size without getting scroll bar – Sravya Sep 16 '14 at 06:33
  • @Sravya: You should use `shrinkToFit:false` if you need exact column size. In the case the grid can have free space on the right size or horizontal scroll bar. By the way do you try to use the second parameter of `setGridWidth`? – Oleg Sep 16 '14 at 06:49
  • Hi Oleg, thanks for your help, i solved out my problem, and one more help, i am unable to set caption(column name)(title) for rownumbers:true; you given answer for that but i am not clear about that, could you provide me any example for that, sorry for asking you again. – Sravya Sep 16 '14 at 08:19
  • @Sravya: Sorry, I'm busy today and tomorrow and have no time for stackoverflow. Try `$('#list1').jqGrid("setLabel", "rn", "Nr:");` – Oleg Sep 16 '14 at 08:47
  • Thanks Oleg, It's enough for me, it is perfectly working – Sravya Sep 16 '14 at 09:20
  • Hi Oleg, how to trigger the event when sort icon is clicked, like if ascending icon is clicked it should alert like "you clicked on ascending order". – Sravya Sep 17 '14 at 10:54
  • 1
    @Sravya It's unfair to keep coming back and altering the initial requirement or asking new questions in the comments. If you have more problems, then ask a new question. – Taryn Sep 17 '14 at 11:13
  • Hi bluefeet, i posted this as a new question, i did'n get any replies that's why i asked here – Sravya Sep 17 '14 at 11:19
  • @Sravya: I have my main job. I was the whole day at the customer today for example. If I post many answers about jqGrid, it doesn't mean that I make free jqGrid support for all people over the world. If I have my free time which I ready to invest in helping other people I try to do this, but not more that that. – Oleg Sep 17 '14 at 14:47
  • Hi Oleg, I am just asking for help, if you are able to help, help me or else it's ok. – Sravya Sep 18 '14 at 07:11