This is a migrated thread and some comments may be shown as answers.

Recreating the Grid will not Group

6 Answers 78 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Chris
Top achievements
Rank 1
Chris asked on 02 May 2013, 07:34 PM

All... I have to change the Grid Layout on an user selection. So the grid will have different column layout and different datasource set for each User selection..
So I did the obvious chose of a Kendo Newbe ... I destroyed the previously created Kendo grid, cleared the grid inner html and recreated the kendo grid using the new column values
Everything works fine.. but after the second selection (first selection is when the kendogrid is first created) ... the grouping wont work ..

any lime light on this issue is appriciated...
Here is the code snippit..
 
<div id="grid" style="height: 380px"></div>

var ViewGridId = 'grid';
var ViewGrid = $("#" + ViewGridId).data("kendoGrid");          
if (ViewGrid) {
 ViewGrid.destroy();
 }
$("#" + ViewGridId).html('');
$("#" + ViewGridId).kendoGrid({
                    dataSource: {
                        data: DataSourceArray,
                        pageSize: 5
                    },
                    change: TryCrmView_FetchXmlMethod.ViewGrid_onChange,
                    selectable: "single",
                    groupable: true,
                    sortable: true,
                    pageable: {
                        refresh: true,
                        pageSizes: true
                    },
                    columns: ColumnsArray
                }); 

 

 

 

 

6 Answers, 1 is accepted

Sort by
0
Atanas Korchev
Telerik team
answered on 03 May 2013, 12:47 PM
Hi Chris,

 We cannot reproduce this behavior in this demo: http://jsbin.com/oqijaq/1/edit

 Could you please modify it so it mimics your case and issue?

All the best,
Atanas Korchev
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Chris
Top achievements
Rank 1
answered on 03 May 2013, 07:11 PM
Atanas -

i am attaching the html  file along with this post.. just modify the kendo file location as urs..I am changing the Column layout based on user selection... But after the first one the Grouping wont happen...

Another weird thing i noticed is... When changing the column layout.. if you dont empty the Div inner html, the column header wont show up... anyway that gets fixed if we clear the div before recreating the kendogrid...

Let me know what you find out... or what i missed...

Well i tried to upload the HTML file...the page wont .. so here is the code...
<script type="text/javascript">
        $(document).ready(function () {

            var sViewListDropDownId = 'lstDropDown';
            //var sValue = $("#" + sViewListDropDownId).val();

            var ViewListData = [];
            ViewListData.push({ text: 'First Choice', value: '1' });
            ViewListData.push({ text: 'Second Choice', value: '2' });
            ViewListData.push({ text: 'Third Choice', value: '3' });
            ViewListData.push({ text: 'Forth Choice', value: '4' });

            // create DropDownList from input HTML element
            $("#" + sViewListDropDownId).kendoDropDownList({
                dataTextField: "text",
                dataValueField: "value",
                dataSource: ViewListData,
                index: 0,
                change: ViewListDropDownId_OnChange
            });

            ViewListDropDownId_OnChange();
        });

        function ViewListDropDownId_OnChange() {
                var sViewListDropDownId = 'lstDropDown';
                var sValue = $("#" + sViewListDropDownId).val();

                var ColumnsArray = [];
                var DataSourceArray = [];

                var iValue = parseInt(sValue);
                for (var i = 1; i <= iValue; i++) {
                    ColumnsArray.push({ "field": 'field' + i, "title": 'Field Title' + i });
                }

                for (var j = 0; j < 10; j++) {
                    var IndiData = {};
                    for (var i = 1; i <= iValue; i++) {
                        var sKey = ("field" + i);
                        IndiData[sKey] = 'Value' + +i + j;
                        
                    }
                    DataSourceArray.push(IndiData);
                }
                var ViewGridId = 'grid';
                
                var ViewGrid = $("#" + ViewGridId).data("kendoGrid");
                if (ViewGrid) {
                    ViewGrid.destroy();
                }
                $("#" + ViewGridId).html('');
                //alert("am destroing it..");

                $("#" + ViewGridId).kendoGrid({
                    dataSource: {
                        data: DataSourceArray,
                        pageSize: 5
                    },
                    selectable: "single",
                    groupable: true,
                    sortable: true,
                    pageable: {
                        refresh: true,
                        pageSizes: true
                    },
                    columns: ColumnsArray
                });
        };
    </script>

<input id="lstDropDown" value="1" />
<div id="grid" style="height: 380px"></div>
0
Chris
Top achievements
Rank 1
answered on 03 May 2013, 07:33 PM
Similar changes to your jsbin library worked as expected..
really dont know how else i can try to reproduce..
0
Chris
Top achievements
Rank 1
answered on 03 May 2013, 07:37 PM
Similar changes to the jbin worked... but i wont work in mine..

var ColumnsArray = [];
ColumnsArray.push({ "field": 'foo', "title": 'Foo Field Title'});

$("#grid").kendoGrid({
  dataSource:{
    data: [
      { foo: "bar Value" }
    ],
    pageSize: 5
  },
  columns: ColumnsArray,
  selectable: "single",
  groupable: true,
  sortable: true,
  pageable: {
    refresh: true,
    pageSizes: true
  }
});



$("button").click(function() {
  var grid = $("#grid").data("kendoGrid");
  grid.destroy();
  ColumnsArray.push({ "field": 'bar', "title": 'Bar Field Title'});
 
  $("#grid").empty().kendoGrid({
    dataSource:{
      data: [
        { bar: "foo Value", foo: "bar Value" },
        { bar: "foo Value 1", foo: "bar Value 1" }
      ],
      pageSize: 5
    },
    columns: ColumnsArray,
    selectable: "single",
    groupable: true,
    sortable: true ,
    pageable: {
      refresh: true,
      pageSizes: true
    }
  });
});
0
Chris
Top achievements
Rank 1
answered on 03 May 2013, 07:59 PM
Interesting..
I copied the code i posed in the above post, to my local dev and that had the same problem .. so i swapped the .js files references from the jsbin link to my dev and the grouping worked like a charm..

Apparently the kendo library i have is not the same you have referenced...

0
Atanas Korchev
Telerik team
answered on 06 May 2013, 08:19 AM
Hello Chris,

The jsbin sample I've sent is using the current official release which is 2013.1 319. Perhaps upgrading to this issue would fix the problem.

Regards,
Atanas Korchev
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Tags
Grid
Asked by
Chris
Top achievements
Rank 1
Answers by
Atanas Korchev
Telerik team
Chris
Top achievements
Rank 1
Share this question
or