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

Rebind empty rad grid creates problem

5 Answers 168 Views
Grid
This is a migrated thread and some comments may be shown as answers.
ali zubair
Top achievements
Rank 1
ali zubair asked on 04 Jun 2010, 07:31 AM
Hi All,

I gave empty data source to rad grid.
Empty data source is bonded successfully from client side. but when i want to add new record then i call web service method which inserts record in data base successfully after that i call getAllRecords method to which get all records from data base and returns list.

But when i bind it rad grid, it throws javascript error. tableView12 is null. Here is my code.

function InsertUpdateRecord(result)
    {              
        //var tableView12 = tableView1.get_masterTableView();
        var tableView12 = $find("ControlsStudentRecordAdd_rgAddress").get_masterTableView();      
        tableView12.set_dataSource(result[0].objStudentAddressCollection);
        tableView12.dataBind();
    }

I hope i have clear my point of view. if it is not then do let me know i will try to explain it.

how can i do this task.

5 Answers, 1 is accepted

Sort by
0
Accepted
Veli
Telerik team
answered on 09 Jun 2010, 09:05 AM
Hi ali,

When binding RadGrid to an empty data source initially, you need to make sure the RadGrid structure is still created. The column headers should be initialized and showing. This will ensure the RadGrid client objects are fully created. If nothing is shown in RadGrid except for the wrapper element borders then the MasterTableView client object is not initialized and you cannot rebind the table.

Regards,
Veli
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
ali zubair
Top achievements
Rank 1
answered on 09 Jun 2010, 09:09 AM
Thank you so much.

but one more question is that Is there any possibility that initially in bind rad grid with empty data source and also do not want to show header and after when i provide actual data source then show headers too.???
0
Veli
Telerik team
answered on 10 Jun 2010, 02:56 PM
Hi ali,

I believe you can hide the header item from the server if there are no data items. You need to use Display="False" so that the header is still rendered. You can do this in the PreRender event:

protected void Page_PreRender(object sender, EventArgs e)
{
    if (RadGrid1.Items.Count == 0)
    {
        //hide the header of the master table
        RadGrid1.MasterTableView.GetItems(GridItemType.Header)[0].Display = false;
        //optional. hide the item showing you the no records message
        RadGrid1.MasterTableView.GetItems(GridItemType.NoRecordsItem)[0].Display = false;
    }
}


Greetings,
Veli
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
ali zubair
Top achievements
Rank 1
answered on 11 Jun 2010, 06:38 AM
I want it on client side.
0
Veli
Telerik team
answered on 15 Jun 2010, 07:00 AM
Hi ali,

You can use RadGrid's client-side GridCreated event then:

function gridCreated(sender, args)
{
    var master = sender.get_masterTableView();
    if (master.get_dataItems().length === 0)
    {
        for (var i = 0; i < master.get_element().rows.length; i++)
        {
            master.get_element().rows[i].style.display = "none";
        }
    }
}


All the best,
Veli
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
Tags
Grid
Asked by
ali zubair
Top achievements
Rank 1
Answers by
Veli
Telerik team
ali zubair
Top achievements
Rank 1
Share this question
or