Solved

Can't sort by date on jqgrid

Posted on 2011-09-12
1
1,122 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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
This article discusses how to create an extensible mechanism for linked drop downs.
Viewers will get an overview of the benefits and risks of using Bitcoin to accept payments. What Bitcoin is: Legality: Risks: Benefits: Which businesses are best suited?: Other things you should know: How to get started:
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

863 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

23 Experts available now in Live!

Get 1:1 Help Now