quarta-feira, 11 de julho de 2012

ASP.NET MVC Intercept AJAX

Hello,

If you want to change the behavior  how the WebGrid works, you could use this snippet..


 var filter= { "filterd": "false", "page": "", "sort": "", "sortdir": "" };
$(function () {
    $('#yourGRID th a,#yourGRID tfoot a').live('click', function (event) {
        event.preventDefault();
        var href = $(this).attr("href");
        var queryString = href.substring(href.indexOf('?'), href.length);
        queryString = queryString.replace("?", "");
        var arr = queryString.split('&');
        var obj = {};
        for (var i = 0; i < arr.length; i++) {
            var bits = arr[i].split('=');
            obj[bits[0]] = bits[1];
        }
        filter.page = obj.page;
        filter.sort = obj.sort;
        if (filter.sortdir == "DESC" || filter.sortdir == null)
            filter.sortdir = "ASC";
        else
            filter.sortdir = "DESC";
        SearchFuncion();
    });


function SearchFuncion() {
    $("#yourGRID ").load('http://www.yourdomain.com/list', filtros, function (responseText, textStatus, XMLHttpRequest) {
        if (textStatus == "error") {
            alert( XMLHttpRequest.responseText);
        }
    });
}

Postar um comentário