1

I seem to be havign yet another problem with jqGrid :-( I am trying to get the current row data using getRowData, but all I get back is an array [object, Object]. What am I doing wrong?

 This is what I'm using 

var rowdata = $("#list").jqGrid('getRowData');

Can somebody help?

thanks

SimpleUser
  • 1,341
  • 2
  • 16
  • 36
  • The data returned by `getRowData` are always array, but the types of the elements should be strings. It can be that you use some formatter in a wrong way or call `getRowData` in wrong place (for example during editing of data). You should in any way include more your code which defines jqGrid and clear shows in which context you call `getRowData`. – Oleg Oct 16 '11 at 15:33
  • Hi Oleg, thank you for your quick response. This is how I'm calling the method $("#list").jqGrid('navButtonAdd', '#pager', { caption: "", title: "Print Grid",buttonicon: "ui-icon-print", onClickButton: function () {var rowdata = $("#list").jqGrid('getRowData');}}); Basically all I'm trying to get is the list of currently displayed collumns in the grid, so I can feed it to a print action method I have (in my asp.net MVC controller). I'd appreciate any help. Thank you – SimpleUser Oct 16 '11 at 15:49
  • In terms of the formatter, I am using the date formatter on 2 fields:{name: 'Assigned Date', index: 'assignedDate', width: 80,align:'left', sortable: true,formatter: 'date',formatoptions:{newformat: "d-M-Y" },editable: true, edittype: 'text', editoptions: { dataInit: function (el) { $(el).datepicker({ dateFormat: "dd-M-yy" }); }, defaultValue: function () { return getCurrDate();}}, searchoptions: { sopt: ['cn', 'eq', 'ne', 'bw', 'ew', 'nc'] } }, I am not in Edit mode either when I'm calling the method. It is actually defined in a custom button that has been added to the navigator toolbar. – SimpleUser Oct 16 '11 at 16:19
  • The controller work on the *server* side and it has already all data from the jqGrid (the controller sent the data to jqGrid before). Could you explain why you need it. – Oleg Oct 16 '11 at 16:35
  • Hi Oleg, Perhaps I am wrong here, but I do not see a print option for the Grid. I want to allow the user to print the grid as either PDF or Excel. And I want it to include all the rows that satisfy the current query, not just the current rows in the grid. Oh and I also allow the user to turn on/off columns in the grid and the print function has to take this into consideration. To start this process off, I was first trying to get a list of all currently displayed columns in the grid and I got stuck as I mentioned. If you have any way of accomplishing what I'm trying to do, please guide me. – SimpleUser Oct 17 '11 at 07:06

1 Answers1

0

After reading in the comments additional information about your problem I would recommend you following.

If you need to print the page which contains jqGrid you could need to prepare additional CSS for media="print". See here for additional information.

The method getRowData called without parameters give back the array of rows which are array of visible cells. For every cell will be called unformatter, so the data could be not identical to to data which you posted to jqGrid. Moreover if you use data paging or filtering you can have another problem: only visible cells from the current page will be returned back.

I personally prefer to use export to Excel instead of printing the pages. In the case I add an custom button in the navigator bar. If the button will be clicked by the user the request to the corresponding MVC controller action will be sent. The server get all data for the corresponding grid from the database and generate XLSX Excel data as stream with respect of Open XML SDK. The corresponding code is not very small, but in the way one can generate perfect Excel file formatted like it is required. In the case you don't need install Microsoft Office on the server side. The user just opens Excel with all data if he/she clicks the "Export to Excel" button in the jqGrid. In Excel there are very good printing possibility. The most users knows Excel very good and can customize the data (hide some columns for example) before printing.

So my suggestion to you to spend some time in implementing export to Excel instead of implementing printing of jqGrid directly.

Community
  • 1
  • 1
Oleg
  • 220,925
  • 34
  • 403
  • 798
  • Thanks Oleg. That is exactly what I'm trying to do. With one additional condition, I do not want to print all columns by default. If the user has selected/unselected columns in the grid, I want to only print the select3ed ones. Which is where the gridRowData function comes in, just to get the list of selected columns. If you know any other way to get this list, I'd appreciate that. Once again, thank you for taking the time out to help. – SimpleUser Oct 18 '11 at 04:31
  • I have resolved this issue btw. I will soon put a link to my blog showing my workaround for anybody else stuck the same way. Thanks – SimpleUser Oct 31 '11 at 11:57