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

variable is set to null after jquery appendTo

3 Answers 82 Views
Grid
This is a migrated thread and some comments may be shown as answers.
piotre6
Top achievements
Rank 1
piotre6 asked on 17 Jul 2012, 11:52 AM

I have grid on my page located in div with id "Lists":

<div id="Lists"
    <telerik:RadGrid runat="server" ID="mygrid"
    <ClientSettings> 
        <ClientEvents OnGridCreated="document_Grid_OnGridCreated" /> 
    </ClientSettings
    </telerik:RadGrid
</div>
<div id="ParentList">
</div>

when grid is created documentGrid variable is set with that grid:

<script type="text/javascript" >
    var documentGrid = null;
    function document_Grid_OnGridCreated(sender, args) {
        documentGrid = sender;
    }
</script>

to this point everything seems to be fine, I can call following code:
function updateDocumentGrid(){
    documentGrid.get_masterTableView().rebind();
}

after I move Lists div inside another div with id ParentList
global variable window.documentGrid is null.

is there any way to prevent variable documentGrid from beeing set to null?

3 Answers, 1 is accepted

Sort by
0
Kostadin
Telerik team
answered on 20 Jul 2012, 11:44 AM
Hello Piotr,

I tried to reproduce your issue but to no avail. I attached a small sample where documentGrid variable is set with the grid. I place the RadGrid in div with id List and append it to another div with id ParentList as in your scenario. Could you please check it and let me know how it differs from your real setup? Also could you make the appropriate changes in my project, so I can test it locally?

Kind regards,
Kostadin
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
0
piotre6
Top achievements
Rank 1
answered on 20 Jul 2012, 09:23 PM
Hi Kostadin,
thank you for sending me project. I've tried to reproduce my error using your code but I didnt manage.
I've added many files from my project (controls, scripts, images etc.) and finally I got same error.
Please run attached project and put breakpoint to file Scripts/Document.js at line 72.
After line is passed - function appendTo is called documentGrid is set with null value.

I hope you will get same result and will be able to help. I came with temporary solution which is commented line 73
however I'd be glad to know what cases the problem and how to get rid of it.

I couldn't upload project so I've uploaded it to sendspace:
http://www.sendspace.pl/download/YTo0OntzOjc6ImRhdGVfaW4iO2k6MTM0MjgxOTMzNjtzOjU6InRpdGxlIjtzOjc6InRlbGVyaWsiO3M6OToiZmlsZV9uYW1lIjtzOjIzOiJ2YXJpYWJsZWlzc2V0dG9udWxsLnJhciI7czo1OiJ0b2tlbiI7czoyMzoiOGVjOGMyMjZkNzg0NTU2NWI5OWJmZmIiO30dfASDF34vasd3245bvs

Thanks,
Piotr
0
Accepted
Kostadin
Telerik team
answered on 25 Jul 2012, 03:46 PM
Hello Piotr,

The script that you have in DocumentsList.aspx file causes the problem. When you move a container inside another container the script is perform again and set the variable "documentGrid: to null, as in your case. You can simply fix that as you move the script outside the container.
<script type="text/javascript" >
    var documentGrid = null;
    function document_Grid_OnGridCreated(sender, args) {
        documentGrid = 1;
    }
</script>
<div id="DocumentList" style="display:none; height:100%">


All the best,
Kostadin
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
Tags
Grid
Asked by
piotre6
Top achievements
Rank 1
Answers by
Kostadin
Telerik team
piotre6
Top achievements
Rank 1
Share this question
or