Solved

Can't sort by date on jqgrid

Posted on 2011-09-12
1
1,095 Views
Last Modified: 2013-11-19
Hi,

I'm very new to jquery and need some urgent help.  I have a jqgrid which is returning data, however, it needs to be sorted by date in descending order when it is loaded.  I have copied the function here:

            loadComplete: function() {
                if (jQuery(grid).jqGrid('getGridParam', 'records') == 0) {
                    // #divsearchtab').tabs
                   
                    $("#divsearchtab").tabs("disable", tabid-1);
                }
            $("#divsearchresults").append(returnSearchResults("Q&R", jQuery(grid).jqGrid('getGridParam', 'records')));
            },
            colNames: ['ID', 'Title', 'Forum', 'Category', 'Date', 'EmailAddress', 'Author'],
            colModel: [
                   { name: 'ID', index: ID', width: 5, sortable: true, hidden: true },
                      { name: 'SubjectText', index:'SubjectText', width: 300 ,sortable: true},
                       { name: 'DiscForumName', index:'DiscForumName',width: 150 ,sortable: true},
                        { name: 'CategoryName',index:'CategoryName', width: 200, sortable: true },

                       { name: 'AskedWhen', index:'AskedWhen', width: 160, align:'center', sorttype:'date', formatter: 'date', formatoptions: {srcformat: "d-m-Y H:i:s", newformat: "Y-M-d H:i:s"}},
                        { name: 'EmailAddress', width: 100, hidden: true },
                         { name: 'Author', width: 100, hidden: true }
                 ],
            rowNum: 50, height: 350,
            rowList: [20, 30, 50, 100, 500],
            pager: pager,
            sortname: 'AskedWhen',
            //sorttype: 'date',
            //loadonce: true,
            viewrecords: true,
            sortorder: "desc",
            caption: search
        });
        jQuery(grid).jqGrid('navGrid', pager, { del: false, add: false, edit: false });

    });

I also have to format the date column to a specific format. Also, can someone please explain to me what srcformat means and newformat means?

I have also supplied some of the JSON data that is usded for this grid from firebug:

cell ["25", "Example Measurement", "iceForum", 4 more...]
0 "25"
1 "Example Measurement"
2 "iceForum"
3 "30 - Instruments and Control"
4 "08/06/2002 16:15:59"
5 "test@mail.com"
6 "Mark Smith"
id "25"

if anyone can help me then that would be great!

Cheers,

-BIZ-
0
Comment
Question by:-BIZ-
1 Comment
 
LVL 82

Accepted Solution

by:
leakim971 earned 500 total points
ID: 36524883
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

OverviewThis article demonstrates a simple search form using AJAX. The purpose of the article is to demonstrate how to use the same code to render a page and javascript (JQuery) and AJAX to make subsequent calls to refine the results. The princip…
JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to dynamically set the form action using jQuery.

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now