Click here to Skip to main content
15,884,838 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
Show me some examples that i can use in my project with details

JavaScript
function Sorting(columnName, cityId, tabid) {
    if (sort == "ASC") {
        sort = "DESC";
    } else {
        sort = "ASC";
    }
    $.ajax({
        type: "GET",
        contentType: 'application/json',
        url: "/VisitorList/Sorting",
        data: {
            Id: currentPage,
            cityId: cityId,
            searchType: tabid,
            columnName: columnName,
            sortType: sort
        },
        success: function (data) {
            $('#divVisitorsList').html(data);
            sort = data.Sort_Direction;
        }
    });
}

$('.sorting').click(function (evt) {
    var columnName = $(this).text();
    var cityId = $('#ddlLocation').val();
    var tabid = $(".VisitorActiveTab").find('.active').attr('id');
    Sorting(columnName, cityId, tabid)
});
Posted
Updated 6-Oct-15 3:33am
v3

Use jquery datatable to bind your table. Which will give you sorting,paging all functionalities by default without refreshing page.

can refer this link
https://datatables.net/examples/basic_init/table_sorting.html[^]
 
Share this answer
 
Comments
Chivillaz 6-Oct-15 10:26am    
is not working
In your sorting action method, return the partial view with the data, and on jquery ajax success call, replace your table with new data.
C#
public ActionResult Sorting(your params)
{
    // your logic
    return PartialView("_PartialViewName.cshtml", result);
}


JavaScript
$.ajax({
    type: "GET",
    contentType: 'application/json',
    url: "/VisitorList/Sorting",
    data: { Id: currentPage, cityId: cityId, searchType: tabid, columnName: columnName, sortType: sort },
    success: function (data) {
            $('#divVisitorsList').replaceWith(data);  // this is important
            sort = data.Sort_Direction;
        }
});


-KR
 
Share this answer
 
Comments
Chivillaz 6-Oct-15 9:44am    
how can i show a value of sort_direction ,this is the property of one of my domain class
i used a alert(data.sort_Direction);
but its shows undefined,because it return the whole div content but i want only the particular value of the Sort_direction
Krunal Rohit 6-Oct-15 14:01pm    
http://www.asp.net/mvc/overview/getting-started/getting-started-with-ef-using-mvc/sorting-filtering-and-paging-with-the-entity-framework-in-an-asp-net-mvc-application

Refer this, you'll get an idea ;)

-KR
Chivillaz 7-Oct-15 0:58am    
its working but the whole page is refreshing but i want to refresh only div tag
Chivillaz 7-Oct-15 1:00am    
i have already tried that earlier on..
Chivillaz 7-Oct-15 1:20am    
anything else
Please refer to this great article on CP for full details on the implementation without any refresh:

Enhancing HTML tables using the jQuery DataTables plug-in[^]

Hope this helps!
 
Share this answer
 
Comments
Chivillaz 6-Oct-15 9:51am    
i have used the above code but the problem is that sortingis happening only on page loading if i again click that same button its does not happen any more and i want to refresh only the div content not the whole page
Palash Mondal_ 6-Oct-15 10:00am    
Try replacing

$('.sorting').click(function (evt) {

with

$(document).on('click', '.sorting', function (evt) {
Chivillaz 6-Oct-15 10:03am    
not working its the same thing
Chivillaz 6-Oct-15 10:05am    
and one thing after clicking one column the next column is not working on the same page load for do sorting by next column i have TO refresh the page
Palash Mondal_ 6-Oct-15 10:07am    
Please post the /VisitorList/Sorting code. want to see what logic you are using to sort there.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900