Welcome Guest Search | Active Topics | Sign In | Register

Eo.Grid: adding new items question Options
hantymansy
Posted: Monday, October 24, 2011 7:02:29 AM
Rank: Newbie
Groups: Member

Joined: 10/24/2011
Posts: 2
I have a EO.Grid on my page based on the example from demo code

http://demo.essentialobjects.com/Demos/Grid/Features/Custom%20Column%20-%20Advanced%202/Demo.aspx

when I click on the row marked * and don't enter or select anything a new item is added to the grid. Is there a way to control that either on client or server side as I don't want the grid to add items that contain nothing.
eo_support
Posted: Monday, October 24, 2011 10:19:28 AM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,194
Hi,

The easiest way is to not saving empty rows back to your data source. When the page posts back, you will get a list of new items through the Grid's AddedItems property. You would then loop through that property to check which item is not empty and save it back to your data source (thus skipping empty items). After that you can rebind the Grid from your data source. This process effectively eliminates the empty items.

Thanks!
hantymansy
Posted: Tuesday, October 25, 2011 1:59:27 AM
Rank: Newbie
Groups: Member

Joined: 10/24/2011
Posts: 2
As I understood it's impossiible to take the full control over the grid when it adds new items. That would be great if there was a metod to check if an item being added contains empty cells. If that method returns true then append an item.
eo_support
Posted: Tuesday, October 25, 2011 8:32:26 AM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,194
Hi,

You can do that with our client side JavaScript interface by handling ClientSideAfterEdit event. You would check each cell's value inside that event and then delete the item if all cells are empty. Make sure you call your code from setTimeout. For example:

Code: JavaScript
function your_after_edit_handler(item)
{
    setTimeout(function()
    {
        delete_empty_item(item);
    }, 100);
}

function delete_empty_item(item)
{
    //check whether the item is empty and delete it if it is
    ....
}


If you have not used our client side API before, you will need to take a look of this topic:

http://doc.essentialobjects.com/library/1/clientapi_howto.aspx

Hope this helps.

Thanks!


You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.