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

[Solved] Moving Rows

0 Answers 97 Views
Grid
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
AspenSquare
Top achievements
Rank 1
AspenSquare asked on 23 Aug 2012, 02:57 PM
Is it possible to move rows via a button click?

From my View:
@(Html.Telerik().Grid(Model.Assets)
    .Name("ImageSliderGrid")
    .DataKeys(k => k.Add(p => p.AssetID))
    .DataBinding(db => db.Ajax()
        .Delete("DeleteAsset", "Asset")
        .Update("UpdateGalleryImage", "Asset")
    )
    //.Selectable()
    .Columns(col =>
    {
        col.Bound(o => o.AssetID);
        col.Bound(o => o.Position);
        col.Bound(o => o.Title).Title("Title").Width(200);
        col.Bound(o => o.Body).Width(300);
        col.Bound(o => o.Location2).Encoded(false).Title("Image").ReadOnly(true);
        col.Template(@<text><img src="../../Content/images/icon_up.png" onclick="movePosition(@item.AssetID,'-1',@item.AssetSubTypeID,@item.Position);" style="cursor: pointer;" alt="Move Up" /><img src="../../Content/images/icon_down.png" onclick="movePosition(@item.AssetID,'1',@item.AssetSubTypeID,@item.Position);"  style="cursor: pointer;" alt="Move Down" /></text>);
        col.Command(commands =>
        {
            commands.Edit();
            commands.Delete();
        });
    })
)


Javascript function that I'm calling from my button onclick events.

function movePosition(assetID, direction, assetSubTypeID, position) {
    var propID = $("[id^='PropID']").val();
 
    $.ajax(
    {
        type: "POST"
        , url: "/Asset/ChangeOrder"
        , data: { "AssetID": assetID, "Direction": direction, "AssetSubTypeID": assetSubTypeID, "PropID": propID, "Position": position }
        , dataType: "text"
        , success: function (data) {
            //e.data = { AssetID: assetID, Direction: direction, AssetSubTypeID: assetSubTypeID, PropID: propID, Position: position };
            refreshGrid();
        }
        , error: function (error) {
            //$("#ImageSlider-list-holder").html();
            alert("There was an error trying change image order.");
        }
    });
}
 
 
function refreshGrid() {
    //alert('refresh it now!!!');
    //$(".t-grid .t-refresh").trigger('click');
 
    var grid = $('#ImageSliderGrid').data('tGrid');
    grid.rebind();
}


The ActionResult in my Controller if firing properly and my database is getting updated but I'm having issues refreshing the grid.
[HttpPost]
[GridAction]
public ActionResult ChangeOrder(Int32 AssetID, Int32 Direction, Int32 AssetSubTypeID, Int32 PropID, Int32 Position)
{
        ...
        ...
        ...
        return View(new Telerik.Web.Mvc.GridModel(_updatedList));
}

Tags
Grid
Asked by
AspenSquare
Top achievements
Rank 1
Share this question
or