Jqgrid: Export to excel sorting according to jqgrid table - export-to-excel

I have added in my jqgrid to load the content in descending order. But (using OpenXML) after exporting, my data are not in descending order.
Can anyone help to get the solution?
I have added sortname:'Cust_ID' sortorder: "desc" under load jqgrid but this mentioned column Cust_ID is hidden in jqgrid. Now I would like to sort the same as my jqgrid
Below if my export to excel function.
`public string ExportReport(int cp, int noOfOrders)
{
string conndb=ConfigurationManager.AppSettings["Db"];
const string Ids ="0";
Company pList = _items.GetByCID(cp);
IQueryable<Product> List
List=product.SQLDatabase().GetListByCompandIds(cp, Convert.ToInt32(noOfOrders), conndb, Ids)
XLWorkbook workbook = new XLWorkbook(XLEventTracking.Disabled);
IXLWorksheet worksheet = workbook.Worksheets.Add("ListReport");
worksheet.Cell(1, 1).Value = "Date";
worksheet.Cell(1, 2).Value = "First Name";
worksheet.Cell(1, 3).Value = "Last Name";
worksheet.Cell(1, 4).Value = "Email";
worksheet.Cell(1, 5).Value = "Department";
worksheet.Cell(1, 6).Value = "Supervisor";
int i = 2;
foreach (EList ExpReport in List)
{
worksheet.Cell(i, 1).SetValue(ExpReport.Date);
worksheet.Cell(i, 2).SetValue(ExpReport.FirstName);
worksheet.Cell(i, 3).SetValue(ExpReport.LastName);
worksheet.Cell(i, 4).SetValue(ExpReport.Email);
worksheet.Cell(i, 5).SetValue(ExpReport.Department);
worksheet.Cell(i, 6).SetValue(ExpReport.Supervisor);
++i;
}
worksheet.Columns().AdjustToContents();
Session["Workbook"] = workbook;
string filename;
filename = "Product-Report";
return filename;
}`

Client side sorted data in jqGrid CAN NOT be accessed directly from code behind.
Alternatively, you can get the currently sorted column name from jqGrid in JavaScript, store it in a hidden field (or server control) that can be accessed from code behind, and then apply it to database query in your ExcelExport function.
For using hidden variable you may follow Persist-JavaScript-variables-and-objects-across-PostBack-in-ASPNet.aspx
In yet another approach you may get sorted column name from jqGrid in JavaScript and then use AJAX call to pass it to a WebMethod in code behind (or Web API / Script Service / Web Service such as asmx, ashx) which exports data to excel by sorting the data in required order.
For making ajax post you may refer to using-jquery-to-make-a-post-how-to-properly-supply-data-parameter For AJAX call and WebMethod usage you may follow Send-Pass-multiple-parameters-to-WebMethod-in-jQuery-AJAX-POST-in-ASPNet
If you need any reference for getting sorted column name you can refer how-to-get-the-current-sort-column-in-a-jqgrid-after-user-clicks-a-column-header

Related

Oracle ADF LOVs value binding to multiple text fileds

I have a use case where I have created a view object that contains 3 values namely LOC_CODE, LOC_DESC, CITY_DESC. Now in my ADF form I would like to display all 3 values in such a way so that user would have a provision to select LOC_CODE From Popup(LOV) and rest two fileds LOC_DESC & CITY_DESC should be changed accordingly. Currently the popup shows all 3 values but when I select the row and click on OK button it only fills the LOC_CODE in 1 textbox.
Below is the scenario of the same:
Got the solution. Just need to add a textbox or drag and drop near respective field and bind it with required binding object. For e.g. in this case LOC_DESC & CITY_DESC is available in my data control as DefLoc & DefCity that contains SQL to fetch respective description value. Now I need to drag and drop DefLoc & DefCity and binding is automatically done or just check binding in value.
you have to add valuechangelistener to location code. set autosubmit true.
now in backing bean use following code:
public void valuechangelistener(ValueChangeEvent valueChangeEvent) {
valueChangeEvent.getComponent().processUpdates(FacesContext.getCurrentInstance());
BindingContext bctx = BindingContext.getCurrent();
BindingContainer bindings = bctx.getCurrentBindingsEntry();
JUCtrlListBinding list = (JUCtrlListBinding)bindings.get("LOC_CODE");
String selectedValue = (String)list.getAttributeValue();
list.getListIterBinding().setCurrentRowWithKeyValue(selectedValue);
Row currRow = list.getListIterBinding().getCurrentRow();
if (currRow != null) {
bndloc_desc.setValue(currRow.getAttribute("LOC_DESC"));
bndcity_desc.setValue(currRow.getAttribute("CITY_DESC"));
}
}
now set partial trigger to both location desc and city desc with id of LOC_CODE.
After doing this you will get your desired result.
update after implementing it.
In my case JDeveloper 12.2.1.3.0
public void valueChangeListener(ValueChangeEvent valueChangeEvent) {
BindingContext bctx = BindingContext.getCurrent();
BindingContainer bindings = bctx.getCurrentBindingsEntry();
JUCtrlListBinding list = (JUCtrlListBinding) bindings.get("YourBindingforLOV");
String selectedValue = (String) valueChangeEvent.getNewValue();
list.getListIterBinding().setCurrentRowWithKeyValue(selectedValue);
Row currRow = list.getListIterBinding().getCurrentRow();
if (currRow != null) {
String s = (String) currRow.getAttribute("YourAttributeName");
}
}

Google SpreadSheet Api, Putting List-Based Feeds Which Starts on Specific Cell

As seen as Google Api, i can easily put my data into a spreadsheet as below :
namespace MySpreadsheetIntegration
{
class Program
{
static void Main(string[] args)
{
SpreadsheetsService service = new SpreadsheetsService("MySpreadsheetIntegration-v1");
// TODO: Authorize the service object for a specific user (see other sections)
// Instantiate a SpreadsheetQuery object to retrieve spreadsheets.
SpreadsheetQuery query = new SpreadsheetQuery();
// Make a request to the API and get all spreadsheets.
SpreadsheetFeed feed = service.Query(query);
if (feed.Entries.Count == 0)
{
// TODO: There were no spreadsheets, act accordingly.
}
// TODO: Choose a spreadsheet more intelligently based on your
// app's needs.
SpreadsheetEntry spreadsheet = (SpreadsheetEntry)feed.Entries[0];
Console.WriteLine(spreadsheet.Title.Text);
// Get the first worksheet of the first spreadsheet.
// TODO: Choose a worksheet more intelligently based on your
// app's needs.
WorksheetFeed wsFeed = spreadsheet.Worksheets;
WorksheetEntry worksheet = (WorksheetEntry)wsFeed.Entries[0];
// Define the URL to request the list feed of the worksheet.
AtomLink listFeedLink = worksheet.Links.FindService(GDataSpreadsheetsNameTable.ListRel, null);
// Fetch the list feed of the worksheet.
ListQuery listQuery = new ListQuery(listFeedLink.HRef.ToString());
ListFeed listFeed = service.Query(listQuery);
// Create a local representation of the new row.
ListEntry row = new ListEntry();
row.Elements.Add(new ListEntry.Custom() { LocalName = "firstname", Value = "Joe" });
row.Elements.Add(new ListEntry.Custom() { LocalName = "lastname", Value = "Smith" });
row.Elements.Add(new ListEntry.Custom() { LocalName = "age", Value = "26" });
row.Elements.Add(new ListEntry.Custom() { LocalName = "height", Value = "176" });
// Send the new row to the API for insertion.
service.Insert(listFeed, row);
}
}
}
If i wrote "firstname" into the A1 and "lastname" into the B1, this is working, but i want to start this function ie. F21.
I mean, my localname firstname is in the cell F21 and i want google api to put my data "JOE" into F22 cell and ...
How can i do that ?
Regards.
CellFeed will do that, but list feed is more like an SQL style database table.
Suggest you use CellFeed or update your data SQL style, in whole rows.
I gave up with list feed when I discovered how little control you have over the position of the data.
Good examples:
CellFeed
https://gdata-java-client.googlecode.com/svn-history/r51/trunk/java/sample/spreadsheet/cell/CellDemo.java
ListFeed
https://gdata-java-client.googlecode.com/svn-history/r51/trunk/java/sample/spreadsheet/list/ListDemo.java

jqGrid display enum as string

I'm attempting to use the ASP.Net MVC version of jqGrid to display a simple data grid. One of the columns in my grid is an Enum and jqGrid is displaying is as an int whereas I want to display it as a string. How can I get jqGrid to display it as a string?
new JQGridColumn { DataField = "ApprovalStatus",
DataType = typeof(ApplicationStatusTypes),
Editable = false,
Width = 200},
public enum ApplicationStatusTypes
{
Unassessed = 0,
AssessmentInProgress = 1,
RequirementsNotMet = 2,
RequirementsPartiallyMet = 3,
RequirementsMet = 4,
Approved = 5
}
When the jqGrid is rendered the ApprovalStatus column shows up as an int instead of a string. I've tried messing around with DataFormatString on the column but to no avail.
I see that this is an old question, but for any lost soul, that will come here.
First step is to set a SetFormatter(Formatters.Select) for the column used for displaying an enum.
But then you need to provide a list of enum mappings. jqGrid expects them to be provided as a string in format of enumValue1:enumName1;enumValue2:enumName2 directly to .SetEditOptions(new EditOptions { Value = ... }) - unfortunately the API naming convention is broken here.
The string generation itself is pretty straightforward and can be generalized to the following expression:
string.Join(";", Enum.GetNames(typeof(T)).Zip(Enum.GetValues(typeof(T)).Cast<int>(), (text, val) => val.ToString() + ":" + text));
, where T is generic parameter being an enum type.

How can I fill the text fields in page by selecting combo selection by dyanmicaly?

Suppose in the database there is one table (for example student records) with a number of columns, but my HTML page only displays a few of them. For example: a table having the columns sno, sname, addr, age, dept, and dob and my page having only 3 fields: sno, sname, dept. Here I display the dept field in a combo box control and the rest of the fields are text and empty values.
My requirement is: when I select the dept from combobox the corresponding row vlaues like sno and sname have to display automatically in the text fields. How can I do this?
You make an ajax call to your server when you change the department. Your server returns your object as JSON. Your success handler in your ajax call takes the fields it needs from your JSON object and sets the appropriate html elements to those fields. For example, if you're using jQuery:
var myUrl = "http://some.domain/action/";
var success = function(response) {
$('#textField1').val(response.sno);
$('#textField2').val(response.sname);
}
$('#myDropDown').change(function() {
$.get(myUrl + $(this).val(), success);
});
If you don't want to send back all the properties of your object because you want to minimize bandwidth, you can form your own JSON object, but that's kind of a pain in the neck and if your object is not huge you might as well use whatever JSON serializer is available in the framework you're using and just serialize the object and send it through the wire.
Or here's another option. You could just make one initial AJAX call and then create a map from department to the other fields you want to set. Example:
var map = {};
var success = function(response) {
for (obj in response.objects) {
map[obj.department] = { sno: obj.sno, sname: obj.sname };
}
}
$.get(myUrl, success);
$('#myDropDown').change(function() {
var obj = map[$(this).val()];
$('#textField1').val(obj.sno);
$('#textField2').val(obj.sname);
}
Hope that helps.

selected Picklist value not saving in dynamic CRM?

I have added javascript for reverse the items in the picklist (rating) to the opportunity entity. It is done. but when I am filling the data and saving it, it is not saving the selected item from the rating picklist to the database. What do I have to do?
var oField = crmForm.all.opportunityratingcode;
var items = oField.options.length;
var arrTexts = new Array(items);
var arrValues = new Array(items);
for(i=0;i<items;i++)
{
arrTexts[i]=oField.Options[i].Text;
arrValues [i]=oField.Options[i].DataValue;
}
for(i=0;i<=items;i++)
{
oField.DeleteOption(i);
}
for(j=items;j>0;j--)
{
var oOption1 =oField.Options;
oOption1.Text=arrTexts[j-1];
oOption1.DataValue= arrValues [j-1];
oField.AddOption(oOption1.Text,oOption1.DataValue);
alert(oOption1.DataValue);
}
Sounds like you need to add a .ForceSubmit in the onSave of the form. This forces CRM to save attribute data changes that you have made with JavaScript.
e.g.
crmForm.all.attribName.ForceSubmit = true;
Check the CRM SDK here: http://technet.microsoft.com/en-us/library/cc189831.aspx

Resources