$location.search( ) with ng-click to redirect to the same page without loading

Elton2
Tera Contributor

Hi everyone,

When clicking on the table row, the user will be directed to a form, 

but this form must be on the same page without having to load it. 

 

Obs.: Before the user was clicking on the record and being directed to another page, 

due to this I am using the “sys_id” of the page.

 

I have to use "$location.search", but its not working:

 

<!--HTML-->
<li>
<td  ng-repeat="record in allRecords"  ng-if="options.redirect == 'true'" class="pointer list__short" ng-switch="data.column_types[field.field]">
<span class="record_list" ng-click="$location.search({data.url + sys_id})"></span>
</td>
</li>
 
/*Client Script*/
    /* Redirect */
    $scope.redirect = function (record) {
        if (c.options.redirect == 'false')
            return;

        if (!record) return;
        var url = c.data.url + record.sys_id;
        $window.open(url, c.options.target);
    }
 
 
/*Server Script*/
data.url = $sp.getPortalRecord().getDisplayValue('url_suffix') + '?id=' + page + '&table=' + data.table + '&sys_id=';
 
Could anybody support me?!
Tks
2 ACCEPTED SOLUTIONS

jaheerhattiwale
Mega Sage

@Elton2 Tried and Tested solution.

 

Please try below code:

Server:

data.table = "<TABLE NAME HERE>";
data.view = "<VIEW NAME HERE";
 
HTML:
<li>
<td  ng-repeat="record in allRecords"  ng-if="options.redirect == 'true'" class="pointer list__short" ng-switch="data.column_types[field.field]">
<span class="record_list" ng-click="c.goToRecord(record.sys_id)"></span>
</td>
</li>
 
Client controller:
c.goToRecord = function(recordId){
    var parms = {
        id: 'form',
        table: c.data.table,
        view: c.data.view,
        sys_id: recordId
    };

    $location.search(parms);
};
 
Please mark as correct answer if this solves your issue.

View solution in original post

@Elton2 We can open in same tab also as follows

 

$window.open(url, c.options.target);

 

Change the above line to 

 

$window.open(url, "_self);

OR

In the instance options you should have a target field there, select _self there.

 

Please mark as correct answer if this solves your issue.

View solution in original post

7 REPLIES 7

jaheerhattiwale
Mega Sage

@Elton2 Tried and Tested solution.

 

Please try below code:

Server:

data.table = "<TABLE NAME HERE>";
data.view = "<VIEW NAME HERE";
 
HTML:
<li>
<td  ng-repeat="record in allRecords"  ng-if="options.redirect == 'true'" class="pointer list__short" ng-switch="data.column_types[field.field]">
<span class="record_list" ng-click="c.goToRecord(record.sys_id)"></span>
</td>
</li>
 
Client controller:
c.goToRecord = function(recordId){
    var parms = {
        id: 'form',
        table: c.data.table,
        view: c.data.view,
        sys_id: recordId
    };

    $location.search(parms);
};
 
Please mark as correct answer if this solves your issue.

Elton2
Tera Contributor

Hi @jaheerhattiwale how are you?!


When the user clicks on the Record in the table, user is directed. This URL is created:

new_portal?id=widget_of_new_form&table=kb_all_item&view=WidgetNew


However, the Sys_id of the Registry does not appear in the URL and the order is not correct,
I believe that because that does not create the "object" and also does not direct to the Form page, if direct to page
it would be good too.

for exemplo: data.formPage = $sp.getParameter('id') == 'new_portal_register_form';

 

/*CLIENT SCRIPT*/
c.goToRecord = function(recordId){
var parms = {
id: 'widget_of_new_form',
table: c.data.table,
view: c.data.view,
sys_id: recordId,

};

$location.search(parms);
};

 

Tks again for you support!

@Elton2 Can you please post the screen shots of HTML, Client Script and Server script code?

Elton2
Tera Contributor

Hi @jaheerhattiwale , how are you?

 

I believe you are on the right path, but according to your tips the form does not render on the same page of the Table and the records do not appear.

I have attached pictures

 

Tks again!!