Click here to Skip to main content
15,887,746 members
Home / Discussions / Web Development
   

Web Development

 
GeneralRe: Layout Elements Horizontally Pin
Richard Deeming10-May-17 5:35
mveRichard Deeming10-May-17 5:35 
GeneralRe: Layout Elements Horizontally Pin
Kevin Marois10-May-17 5:40
professionalKevin Marois10-May-17 5:40 
GeneralRe: Layout Elements Horizontally Pin
MikeSpock2-Jun-17 0:38
professionalMikeSpock2-Jun-17 0:38 
QuestionChange WebGrid RowsPerPage During Runtime Pin
Kevin Marois9-May-17 11:43
professionalKevin Marois9-May-17 11:43 
AnswerRe: Change WebGrid RowsPerPage During Runtime Pin
Richard Deeming10-May-17 1:38
mveRichard Deeming10-May-17 1:38 
GeneralRe: Change WebGrid RowsPerPage During Runtime Pin
Kevin Marois10-May-17 6:27
professionalKevin Marois10-May-17 6:27 
JokeRe: Change WebGrid RowsPerPage During Runtime Pin
Richard Deeming10-May-17 7:04
mveRichard Deeming10-May-17 7:04 
QuestionReload WebGrid From Controller Pin
Kevin Marois9-May-17 11:08
professionalKevin Marois9-May-17 11:08 
I have a WebGrid and search field on a page. When the user types anything into the search field, I want to filter the data and reload the grid.

Here's what I have so far:
Controller
public class HomeController : Controller
{
    private IDataAccess _dal;

    public HomeController()
    {
        _dal = new DataAccess();
    }

    public ActionResult Index()
    {
        var args = new DashboardInfoQueryArgs();

        var data = GetData(args);
        return View(data);
    }

    public IEnumerable GetData(DashboardInfoQueryArgs args)
    {
        var data = _dal.GetDashboardInfos(args);
        return data;
    }

    [HttpPost]
    public IEnumerable Search(string searchValue)
    {
        var data = GetData(new DashboardInfoQueryArgs(searchValue));
        return data;
    }
}
HTML
@using (@Html.BeginForm("Index", "Home"))
{

        @{
            var grid = new WebGrid(Model, rowsPerPage: 10, canPage: true, ajaxUpdateContainerId: "divData");

            @grid.GetHtml(
                emptyRowCellValue: "No Records Found",
                htmlAttributes: new { id = "web-grid" },
                mode: WebGridPagerModes.All,
                columns:
                grid.Columns
                (
                    grid.Column("RowId", "Row Id", style: "rowid-column-style", format: @@item.RowId),
                    grid.Column("SiteId", "Site Id", style: "siteid-column-style", format: @@item.SiteId),
                ))
        }

}
JavaScript
$("#searchField").on('change keydown paste input', function () {

    // Get the value the user typed in and pass it to the controller
    var searchVal = document.getElementById("searchField").value;

    $.ajax({
        type: "POST",
        url: '/Home/Search',
        data: { searchValue: searchVal },
        success: function (result) {

            // Here I want to reload the grid from the controller's Seaarch method

        },
        error: function (result) {
            alert('Error!');
        }
    });

});

Everytging seems to be working, except I don't know to reload the WebGrid once the Search method on the controller is done.

Am I going about this right? What am I missing?

Thanks
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.

AnswerRe: Reload WebGrid From Controller Pin
Richard Deeming10-May-17 1:04
mveRichard Deeming10-May-17 1:04 
GeneralRe: Reload WebGrid From Controller Pin
Kevin Marois10-May-17 5:55
professionalKevin Marois10-May-17 5:55 
GeneralRe: Reload WebGrid From Controller Pin
Richard Deeming10-May-17 6:08
mveRichard Deeming10-May-17 6:08 
QuestionWebGrid Searching and Filtering Pin
Kevin Marois8-May-17 8:25
professionalKevin Marois8-May-17 8:25 
SuggestionRe: WebGrid Searching and Filtering Pin
Richard Deeming8-May-17 8:45
mveRichard Deeming8-May-17 8:45 
GeneralRe: WebGrid Searching and Filtering Pin
Kevin Marois8-May-17 10:41
professionalKevin Marois8-May-17 10:41 
QuestionMy website inner pages are not crawling and indexed? Pin
Bharathi Karampudi6-May-17 0:26
Bharathi Karampudi6-May-17 0:26 
AnswerRe: My website inner pages are not crawling and indexed? Pin
Richard Andrew x646-May-17 5:35
professionalRichard Andrew x646-May-17 5:35 
GeneralRe: My website inner pages are not crawling and indexed? Pin
Bharathi Karampudi7-May-17 18:04
Bharathi Karampudi7-May-17 18:04 
QuestionRefresh WebGrid Pin
Kevin Marois2-May-17 11:39
professionalKevin Marois2-May-17 11:39 
SuggestionRe: Refresh WebGrid Pin
Richard Deeming3-May-17 10:52
mveRichard Deeming3-May-17 10:52 
GeneralRe: Refresh WebGrid Pin
Kevin Marois3-May-17 10:54
professionalKevin Marois3-May-17 10:54 
GeneralRe: Refresh WebGrid Pin
Richard Deeming3-May-17 11:03
mveRichard Deeming3-May-17 11:03 
GeneralRe: Refresh WebGrid Pin
Kevin Marois3-May-17 12:31
professionalKevin Marois3-May-17 12:31 
GeneralRe: Refresh WebGrid Pin
Richard Deeming4-May-17 0:47
mveRichard Deeming4-May-17 0:47 
GeneralRe: Refresh WebGrid Pin
Kevin Marois4-May-17 7:11
professionalKevin Marois4-May-17 7:11 
GeneralRe: Refresh WebGrid Pin
Richard Deeming4-May-17 7:32
mveRichard Deeming4-May-17 7:32 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.