Solved

Can't sort by date on jqgrid

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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Learn by example how to specify CSS selectors for Selenium WebDriver test automation software.
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
This tutorial demonstrates how to identify and create boundary or building outlines in Google Maps. In this example, I outline the boundaries of an enclosed skatepark within a community park.  Login to your Google Account, then  Google for "Google M…
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

778 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