Angular 9 ng2-smart table - ng2-smart-table

I am using ng2-smart-table, I am trying to do server-side pagination & sorting. I am not able to get how to do it? Once I click on page number it should go to the backend. What function/method/event I have to use, when clicked on page or sort it should go to the function which calls API.
Also I want to add a anchor link to one column, how to do that?
If you provide me some example that will be helpful.
Please help me with the solution. Thanks

You need to configure ServerDataSource with the names of the parameters your server uses for each purpose, after that you can deal with them in the server side.
this.dataSource = new ServerDataSource(this.http, {
endPoint: environment.SERVICE + `your_route`,
dataKey: 'Data',
pagerPageKey: 'offset',
pagerLimitKey: 'limit',
filterFieldKey: 'query',
sortFieldKey: 'sortby',
sortDirKey: 'order',
totalKey: 'Total',
});

Related

How do i get the User Image from a lookup list on Sharepoint 2013?

I'm really stuck with getting the User image from a lookup list using AJAX with SharePoint 2013.
Ok so im getting my data from a Sp list called 'Comments', and im selecting a SP generated field called 'Created By' however on my SP its actually called 'Author'. This field only shows an ID so ive expanded it with OData to get the 'Author' details.
So what im trying to do is set up a custom comment section. So im taking data from the 'Author / Created By' column and outputting that on top of the persons comment. This all works fine!
$.ajax({
url: _spPageContextInfo.webAbsoluteUrl + "/DigiBlog/_api/web/lists/getbyTitle('Comments')/items?$select=Comment,Likes,BlogId,Created,Author/ID,Author/FirstName,Author/LastName,Author/Title&$expand=Author/Id",
type: "GET",
headers: {
'accept': 'application/json;odata=verbose'
},
success: function (data) {
for (var i = 0; i < data.d.results.length; i++) {
var item = data.d.results[i];
self.blogComments.push(item);
//item.FirstName = item.FirstName.toLowerCase();
//console.log(item);
}
console.log("Comment User Info Called");
},
error: function () {
console.log("Comment User Info Error");
}
});
What i want is the picture Url from that user, so i can output an image of that person next to each comment. My Sharepoint is part of big organisation so theres a tonne of restrictions in place, one of which means i can't view the list of users so i can't see what fields i can actually use. Ive seen people use 'Picture' value in the select field, however when i try that the Ajax fails.
url: _spPageContextInfo.webAbsoluteUrl + "/DigiBlog/_api/web/lists/getbyTitle('Comments')/items?$select=Comment,Likes,BlogId,Created,Author/ID,Author/FirstName,Author/LastName,Author/Title&$expand=Author/Id",
All im looking for is the Author Img URl, ive tried Author/[Picture, PictureUrl, PictureUri, Image, ImageUri... and so on]. Ive spent 2 days on this and im not getting anywhere fast!
I either want a way to get the Picture Url or a way to show all the avaiable fields of 'Author' using console so i can find the relevant field i need to select.
Can anyone help? Thanks in advance!
It seems that we could not get picture url directly.
Firstly,you could get user name.
/_api/web/lists/getbytitle('Comments')/items(1)?$select=Owner/Name&$expand=Owner
Secondly,you could use this rest api to get picture url.
/_api/SP.UserProfiles.PeopleManager/GetPropertiesFor(accountName=#v)?#v='domain\username'&$select=PictureUrl
The different versions of rest api versions are introduced here.
Tip:The username obtained in the first step may need to be processed as in the example.

Wordpress REST API search products

Hope that you can help me.
I have a website that runs wooccommerce. I am using the woocommerce rest api. Now on another website what I want to do is create a simple search field where I type something and the search form needs to search through the woocommerce website and return results.
Is there a way I can achieve that ?
Try this:
/wp-json/wc/v2/products?search={{product_name}}
Works for me.
I think no.
The New Version of WooCommerce API (v2) is supports id based calls.
so instead you can get a list of abstract product details in your 2nd website and call back via product id.
/wp-json/wc/v2/products?search={{product_name}}
Is this function working if you are looking a exact product?
If you have a product like MR2050 and another with MR2050K, the result is not as you may expected, cause API rest will return 2 products, not just ONE?
If you use a wc-api-php (PHP library), please follow like this :
require __DIR__ . '/vendor/autoload.php';
use Automattic\WooCommerce\Client;
$woocommerce = new Client(
'http://mydomain', // Your store URL
'ck_****', // Your consumer key
'cs_****', // Your consumer secret
[
'wp_api' => true, // Enable the WP REST API integration
'version' => 'wc/v3' // WooCommerce WP REST API version
]
);
echo "<pre>";
print_r($woocommerce->get('products', ['search' => 'key word']));
echo "</pre>";
This works for me in 2021:
/wp-json/wc/v3/products?search={{productName}}
productName - refers to the input that you enter in the Search box

Pass in user-specified parameters to query a database and return data

I am extremely new to Ruby on Rails, having only a couple days of experience. So far, I have created a new app, and loaded data into the database called name which is comprised of date:string, value:decimal, and unique_id:integer. So now, I can go to "(my local port)/name" and view the table successfully.
What I would like to do is this:
In a new html page, have a SIMILE Timeplot (http://www.simile-widgets.org/timeplot/) with an HTML drop-down list below it in order to select a unique_id and another drop-down box to select a year.
From there, I would like to search through the database and display all of the data on the Timeplot that matches the unique_id and that is in the specified year.
I believe I must make an HTTP GET request for a date_to, date_from, and unique_id, but I do not know how to implement this (admittedly I have been searching the web for ages, but could not figure out the solution).
Any help would be greatly appreciated! Thank you.
Edit: Even just advice on what component to tackle first
First you need to create a route for your search such as this:
match "name/search" to: "name#search" as: "name_search", via: :get
Then if you are using AJAX, and using jQuery you make an HTTP request like this:
$.get("/name/search", {
unique_id: <your_unique_id>,
date_from: <your_date_from>,
date_to: <your_date_to> },
function(result) {
// You do whatever you want with the result here
}
}
P.S:
The Javascript code might not be 100% correct, since I rarely use it.

Using a Return URL Securely

Hopefully this question isn't too naive...
I'm attempting to implement The Giving Lab API in order to allow users of my site to donate to charity.
Using a URL such a this:
https://www.thegivinglab.org/api/donation/start?donationtype=0&amount=10&charityid=84ed3c54-6d8c-41c5-8090-f8ec800f45a7&returnurl=mywebsite.com/
the user is directed to the donation page and then returned to the returnURL after the donation has been made.
I want to be able to add how much the user donated to my databases if they successfully complete a payment. Would it be possible to use the returnURL to do this? Ie could I use a returnURL in the form of mywebsite.com?q="amount_donated" and then use this to update my databases?
I can see that this would allow someone to update my databases by just entering the returnURL into their browser.
Is there a generally better method, that removes this problem?
Many thanks.
Dutch banks use a thing called a sha-sign (and they're probally not the first)
All you have to do is add a key which only you can know:
function makeSecureCode($var1, $var2){
$secretCode = 'example';
$secretKey = '';
$secretKey.= $var1 . $secretCode;
$secretKey.= $var2 . $secretCode;
return sha1($secretKey);
}
Then make the url like this: ?var1=foo&var2=bar&key=5e8b73da0b20481c1b4a285fb756958e4faa7ff1
And when you process the code after payment, makeSecureCode( $_GET['var1'], $_GET['var2']) should be equal to $_GET['key']. If not, someone changed it.
This is a simplefied version with only two vars. You can make it have more input arguments, or an array, whichever you prefer.

Displaying date from mysql in a Jquery Mobile dropdown

I started making an app with use of Jquery mobile(JQM) to be used for a customer database. You should be able to create a customer name, address etc. The information will then be stored in a MySQL database. The part I've got under control.
Now I want to do so that it is possible to retrieve customer number and name of the database again and show them in a drop down menu from JQM.
So something like:
"SELECT
kundenummer, navn
FROM
kundeskema
ORDER BY
id
DESC";
I have my database connection and my php page, but how do I get the information from where I make my sql statement and to my html page? Know it is using AJAX but dont understand how to do. I know it's a fairly simple task, but it's not for me.
plz help
Morten
You can create a PHP file which returns a JSON string of your data. Then do a jQuery ajax call to this PHP file and in the success callback create elements and add them the select element.
e.g.:
$.ajax({
url: myValues.php,
success: function(data) {
template = //create option elements
$('#mySelect').html(template);
}
});
Or
https://github.com/tkompare/projects/tree/master/ajaxexample
This is for a listview but the idea is the same