GridMvc get id attributes from other pages in a paged Grid - javascript

I am using GridMvc to show data from database. GridMvc provide filter and sorting grid which is very useful. But now I meet a problem: I want to use JQuery to get a list of id attributes and pass this list to backend. But the Grid is Paged with 30 records per page. So I can only get a list of 30 ids from Page 1. Here is the paged grid:
What I want to do is get all href values(e.g. get a list of XX from page div). And when user trigger Export button, I define an JS Export function:
$('#Export').click(function () {
//Todo: Select all data from front end. Send a list to backend.
var Items = new Array();
var hrefs = new Array();
$('.pagination li').each(function () {
hrefs.push($(this).find('a').attr('href'));
});
var i = 0;
//var items = DeleteItems();
while (i < hrefs.length) {
//redirected to different pages
document.location.href = '/GridView' + hrefs[i];
//Save data
$('#PCA-grid table').find('.grid-row').each(function (index, item) {
//Find target items
var id;
var $checkbox = $(this).find('.DeleteSelected:first');
//Set a for loop here to
if (!$checkbox.is(':checked')) {
id = Number($checkbox.attr('id'));
if (id != NaN) {
Items.push(id);
}
}
});
i++;
}
//Sent list of ids to backend. Using URL redirect
window.location.replace('/GridView/Export?items=' + Items);
});
The basic thought has been described in code above. What I want to do is get urls from page tag. In while loop, try to redirect to target page and then push id attributes in this page to Items Array. But when I debut using Chrome tool, the while loop is not working as expected. There is no redirection happens.
Am I wrong with this problem? I just want to get id attributes from all pages in current grid and then pass this Items Array to backend. So anyone help me?

As far as I considered, it's hard to get all id attributes that needed to be downloaded with paging in grid. What I did was redirecting page to another view. In that view, I hidden same grid with no paging. And sent ids needed to be downloaded from grid to backend, then generated file for client user.
Not sure whether this way is best practice. But I used this method solved this problem.

Related

Getting the value of # from a url

I have a problem. i have a website am working on. I have created a php script to fetch all the receipts id from the data base using pagination, and all works fine. But the problem is every receipt id, i have added a link so as when clicked a specified results will be displayed without loading the page.
The links are like :
G145252 G785965 and when each link is clicked will show http://test.com/?go=any#G145252
When clicked the page will not reload.
So what i need help with is how can i get G145252 from the url after when the link is clicked using javascript and print it using html?
i need to pass the value to the process.php as a $GET value so the i can load the receipt detail of the clicked id with out reloading the page.
Please note: there are a lot of get values before the #value i need to get out of the url address.
You should not be using the fragment identifier section of the URI for server side related tasks. This section is intended for client-side manipulation only. More info here.
You can use some other means such as query parameters to access this data.
For example, turn this:
http://test.com/enter code here?go=any#G145252
Into this:
http://test.com?go=any&hash=G145252
Then:
function getQueryVariable(variable) {
var query = window.location.search.substring(1);
var vars = query.split("&");
for (var i=0;i<vars.length;i++) {
var pair = vars[i].split("=");
if(pair[0] == variable){return pair[1];}
}
return(false);
}
console.log(getQueryVariable("go")); // any
console.log(getQueryVariable("hash")); // G145252
NOTE: I know this is not the exact answer to your actual problem, but the question itself is presenting a bad practice scenario, thus my suggestion.
Credits for the getQueryVariable function goes to CSS Tricks: https://css-tricks.com/snippets/javascript/get-url-variables/?test=3&test2=5
Let's assume you're using jQuery.
Change all your links so that they have a common class name, lets say 'hashClick' e.g
My Link
To get the hash part when clicked, add a click event handler for those links
$('.hashClick').click( function(event) {
event.preventDefault();
var url = $(this).attr('href');
var hash = url.substring(url.indexOf('#')+1);
alert("You clicked " + hash);
// or at this point you can do an AJAX call
// or GET request to process.php with hash as one of the parameters
})
suppose this is the link
http://test.com/?go=any#G145252
to get the hash value
window.location.hash
which will return you #G145252
and
window.location.hash.substring(1) will return you "G145252"

Fetch localStorage values to other page using id

I am storing the values in localStorage and the values are getting stored through input[type:hidden] and input[type:text].
JS:
$('.proceed_btn').on('click', function() {
// Blank to start with
var order = {};
// Loop through all inputs...
$('input[type="text"], input[type="hidden"]').each(function() {
// ...adding their values as properties
order[this.name] = this.value;
});
// Store that object in JSON format
localStorage.setItem("order", JSON.stringify(order));
});
I want to print these value in other page when the user redirects after submitting the form. I am working on ruby currently. There are many products in the website, so the information in the summary page gets rendered according to that. Is there any way to display specific form details in through there id's?
You can create a partial with .js.erb extension eg _order_partial.js.erb and retrieve the order object as thus:
order = JSON.parse(localStorage.getItem("order"));
// Loop through the object and print out
Then you can render the partial in any of the views file you want to use it.

netsuite saved search multi-select dropdown filter

Does anyone know if there is a way to add a multi-select drop down filter in a suitelet that is displaying a sublist from an already existing saved search. One of the columns is "customer" and I would like to add a drop-down that filters by the customers on the sublist. I already have the code setup, I was just wondering if this could be done. Thanks
You can use your suitelet as
if (request.getMethod() == 'GET'){
var field = form.addField('custpage_customers', 'multiselect', 'Customers');
var addedCustomers = [], selectedCustomers;
var searchResults= nlapiSearchRecord('transaction','customsearchID');;
//add customers options
searchResults.forEach(function(res){
if(addedCustomers.indexOf(res.getValue('customer')) !== -1) return;
field.addSelectOption(res.getValue('customer'), res.getText('customer'))
});
//filter sublists
//add customer options
if(request.getParameter('customerids')){
addedCustomers = JSON.parse(request.getParameter('customerids'));
searchResults = searchResults.filter(function(res){
return addedCustomers.indexOf(res.getValue(customer)) !==-1)
});
//if above search result reduces your search results you may just want to re-run search as below than filtering it
//searchResults = nlapiSearchRecord('transaction','customsearchID',['customer', 'anyof', JSON.parse(request.getParameter('customerids'))]);
}
//add sublist code goes here
//set a client script
form.setScript(MY_GLOBAL_CLIENT_SCRIPT)
// set response
}
Then write a global client script which would fire on field change
function FieldChanged(type, name)
{
// Prompt for additional information, based on values already selected.
if ((name == YOUR_MULTISELECT_FIELD_ID))
{
//send AJAX with additional argument
nlapiRequestURL(SUITELET_URL + "&customerids=" +encodeURIComponent(JSON.stringify(nlapiGetFieldValue(YOUR_MULTISELECT_FIELD_ID))))
}
}
I generally just go with native elements for things like this and manage them the way you would manage any client side interaction. I generally add a field of type inlinehtml in my suitelet code and then populate the select list with client (field changed and post sourcing) events and AJAX calls.

Parse URL and load corresponding data

I’ve successfully implemented routing and hashing with crossroadsJS and hasherJS on a SPA I’m working on. The data I’m loading from a REST API is entirely event based. This works fine for navigating through the website with click based events. However, I want to implement the ability to type in a URL (or refresh the current view) and load the data corresponding to that URL. I wrote a method like this:
// app.js
app.helpers = {
routeMagic: function (prop, clicked, type, el) {
var parser = document.createElement('a'); // setup parsing
parser.href = hasher.getURL(); // use hasher's .getURL() to find current URL
var splitURL = parser.hash.split('/')[2]; // split at second / ... example: /conditions/annual-wellness-exam => annual-wellness-exam
propArr = []; // set up array to store name property
for (var i=0, len=prop.length; i<len; i++) {
propArr.push(prop[i].name.replace(/,/g, "").replace(/\//g, "").replace(/[()]/g, "").replace(/\s+/g, "-").toLowerCase());
}
$(el).each(function () { // target li ... example ‘.returned-list li’
var val = $(this);
val.id = propArr; // append name to li id
var id = $(this).attr('id');
// this is only executing on click event, need it to execute on refresh or typing in URL
if (splitURL === id) { // find a match
console.log('match found');
clicked = val.children().attr('data-id'); // determine where to route the page to based off data-id
return false;
}
});
type(clicked); // init crossroads routing
}
};
Which would be called like so:
// routes.js
conResultsRoute = crossroads.addRoute('conditions/{name}', function () {
app.helpers.routeMagic(cache.lists.conditions, cache.justClickedCondition, api.endpoints.condition, '.returned-list li');
});
For this example, when I click on a ‘conditions’ link from a list of conditions, the expected results are returned on the following route. However, if I try to type in the same URL, I get a list back of all the data stored in the CMS rather than my filtered list like when I click through the app. I think the problem stems from not being able to target my $(el).each() on page load since it’s held in a different template, or possibly I have to reload my API calls every time I type in a URL. I imagine this isn’t enough data for someone to troubleshoot, so feel free to ask me more questions or check out a live (in development) version here
If you’re visiting the website, try a flow like this:
Conditions (main nav) -> Annual Wellness Exam -> Refresh or hit enter in URL bar

Calling a dialog in Dynamics 2011 and passing multiple recordIDs to it

I want to allow the user to select one or many contacts from the contact entity, and then launch a dialog that accepts the record IDs. The idea is to add some custom configuration to the contacts.
I've currently got a custom action on a ribbon button that launches a dialog, but it only accepts one record Id. I can get access to the list of selected record Ids, thatisn't the problem, it is passing a list to the dialog using JavaScript.
I can't seem to find anything in the SDK or code snippets.
The nearest thing I found was this:
http://crmmongrel.blogspot.com/2011/06/launch-dialog-from-ribbon-button-in-crm.html
Anyone know if this is possible? I know the out of the box Send Direct E-Mail allows an email to be sent to the selected items, so I need something similar.
Should I be using dialogs or something else?
Here is a code snippet of the javascript that is called on the click of the ribbon button:
function LaunchModalDialog(SelectedControlSelectedItemReferences,dialogID, typeName)
{
// Get selected objects
var allItems = new Array
var allItems = SelectedControlSelectedItemReferences
// Just get first item for now as dialog only seems to accept one ID
var personId = allItems[0].Id;
personId = personId.replace(/\{/g, "");
personId = personId.replace(/\}/g, "");
// Load modal
var serverUri = Mscrm.CrmUri.create('/cs/dialog/rundialog.aspx');
var mypath = serverUri + '?DialogID={' + dialogID + '}&EntityName=' + typeName + '&ObjectId={' +personId + '}';
mypath = encodeURI(mypath);
// First item from selected contacts only
window.showModalDialog(mypath);
// Reload form.
window.location.reload(true);
}
You'll need to specify the SelectedControlAllItemIds parameter in your Ribbon for that button. Here is a link that describes it:
http://social.microsoft.com/Forums/en/crm/thread/79f959ac-0846-472f-bff1-4f5afe692a56
--Edit--
I'm sorry, I misunderstood - you meant launch an actual CRM Dialog, not just a normal HTML pop-up dialog window.
CRM Dialogs can't be used on multiple records by design, so you aren't going to be able to use them for this.
However, you should be able to create an HTML web resource file that you can launch from the Ribbon, passing in the SelectedControlAllItemIds parameter. That HTML web resource would then have some javascript that would update the selected contacts using the REST endpoints (see the SDK for more information).
Hope that helps!

Categories