cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
MartinVargas
Helper V
Helper V

Delete blank pages with javascript

Hi community, I am having the following problem. It happens that I implement a filter with javascript to show me only certain data.

The code is the following:

 

$(document).ready(function () {
 
    var list = $("#crd4f_clavearticuo_lookupmodal").find(".entity-lookup").find(".entity-grid").eq(0);

    list.on("loaded", function () {
        
        var IdListaPrecio = "{{user.crd4f_listaprecios}}";
        console.log("IdListaPrecio: " + IdListaPrecio);
        
        if (IdListaPrecio == IdListaPrecio) {
            list.find("table tbody > tr").each(function (index, value) {
                var tr = $(this);
                var tipos = $(tr).find('td[data-attribute="crd4f_idlistaprecios"]').attr("data-value");
                
                if (tipos != IdListaPrecio) {
                   console.log("Tipos: " + tipos);
                    $(tr).remove();            
                }
            });
        }
    });

});

 

 

However, when performing this procedure it shows me the result of the filter between all the pages. For example, the first page does not show me any data:

MartinVargas_0-1639694177407.png

In this example, the results of my filter start to appear until page number 3:

MartinVargas_1-1639694208659.png

 

Is there a way to remove a blank page through javascript?. Or is there some way to solve this?

 

Can anybody help me out here please?

Cheers folks

10 REPLIES 10
chleverenz
Super User
Super User

Hi @MartinVargas ,

no answer, but could it be, that this is the mobile view and the data is split up intop several single "pages"? 

When you remove the pagecontent i would assume, that the pagenavigation is not removed. So, i assume that you also have to remove the corresponding buttons when you remove a specific entry which you do not want to see.

 

If the attribute you are filtering on is a lookup, there is an easier way to filter the stuff: just place the lookup on the form, too and choose in the lookup you want to filter "only related records" and choose the right relation. Then only related records are shown. (you may hide the lookup on the form by js)

 

Ah, you are filtering over a user attribute. When the user should only see valid entries for hers/his user you might conider an entitytablepermission for that. Just create one in contact scope for the targettable which only selects entities which are allowed and assigned it to an appropiate role.

 

Just a couple of ideas, may be it helps.

Have fun,

  Christian

MayankP
Responsive Resident
Responsive Resident

Hi @MartinVargas 

 

my suggestion is to use Add pre-search on relevant look up filed to filter data displayed in look up view...

 

Refer following example article for this..

https://www.inogic.com/blog/2015/08/apply-custom-filter-on-lookup-field-in-dynamic-crm-using-script/

 

 

 

https://mayankp.wordpress.com/2021/08/11/dynamics-365-setting-up-owner-look-up-to-display-only-teams...

 

 

 

Soundharya
Helper III
Helper III

 

Hi,

try below code

What is the data type of this crd4f_idlistaprecios

$(tr).find('td[data-attribute="crd4f_idlistaprecios"]').attr("data-value");
and what are you comparing here tipos != IdListaPrecio
if you are comparing text then it should be as below
$(tr).find('td[data-attribute="crd4f_idlistaprecios"]').attr("
aria-label");

 

$(document).ready(function () {
 
    var list = $("#crd4f_clavearticuo_lookupmodal")..find(".entity-lookup").find(".entity-grid").eq(0);

    list.on("loaded", function () {
        
        var IdListaPrecio = "{{user.crd4f_listaprecios}}";
        console.log("IdListaPrecio: " + IdListaPrecio);
        
       
            list.find("table tbody > tr").each(function () {
                var tr = $(this);
                var tipos = $(tr).find('td[data-attribute="crd4f_idlistaprecios"]').attr("data-value");
                
                if (tipos != IdListaPrecio) {
                   console.log("Tipos: " + tipos);
                    $(tr).remove();            
                }
            });
        
    });

});

 

 

Hi @Soundharya.

The data type "$(tr).find('td[data-attribute="crd4f_idlistprices"]').attr("data-value");" is Text.

 

Here: "types != PriceListId" I am comparing all the list types in the crd4f_priceidlist column against the list type associated with the user.

Both are text fields right then above code should work can you try once, i have modified few

Hi @Soundharya, By implementing the following code:

$(document).ready(function () {
 
    var list = $("#crd4f_clavearticuo_lookupmodal")..find(".entity-lookup").find(".entity-grid").eq(0);

    list.on("loaded", function () {
        
        var IdListaPrecio = "{{user.crd4f_listaprecios}}";
        console.log("IdListaPrecio: " + IdListaPrecio);
        
       
            list.find("table tbody > tr").each(function () {
                var tr = $(this);
                var tipos = $(tr).find('td[data-attribute="crd4f_idlistaprecios"]').attr("aria-label");
                
                if (tipos != IdListaPrecio) {
                   console.log("Tipos: " + tipos);
                    $(tr).remove();            
                }
            });
        
    });

});

It keeps showing me blank pages:

MartinVargas_0-1641236443757.png

 

 

first line there was mistake 2 dots

var list = $("#crd4f_clavearticuo_lookupmodal").find(".entity-lookup").find(".entity-grid").eq(0);

we are trying to remove the row there is no way it will get added, is there any other code on this?
can you paste full code?

i have done the same it is working for me  

MartinVargas
Helper V
Helper V

Hi @Soundharya. This is literally all the code.

 

 

$(document).ready(function () {
 
    var list = $("#crd4f_clavearticuo_lookupmodal").find(".entity-lookup").find(".entity-grid").eq(0);

    list.on("loaded", function () {
        
        var IdListaPrecio = "{{user.crd4f_listaprecios}}";
        console.log("IdListaPrecio: " + IdListaPrecio);
        
       
            list.find("table tbody > tr").each(function () {
                var tr = $(this);
                var tipos = $(tr).find('td[data-attribute="crd4f_idlistaprecios"]').attr("aria-label");
                
                if (tipos != IdListaPrecio) {
                   console.log("Tipos: " + tipos);
                    $(tr).remove();            
                }
            });
        
    });

});

 

 

I got it based on Oliver Rodrigues's exercise: https://oliverrodrigues365.com/2021/01/24/power-apps-portals-custom-lookup-filter/

 

Ya even i tried this , unfortunately this code runs on each page not on all records may be you don't have the data or check on next pages for matching data

i have one record matching in 1st page and other in 2nd page

 

Soundharya_0-1641315897453.pngSoundharya_1-1641315926615.png

 

Helpful resources

Announcements
Power Platform Conf 2022 768x460.jpg

Join us for Microsoft Power Platform Conference

The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform.

365 EduCon 768x460.png

Microsoft 365 EduCon

Join us for two optional days of workshops and a 3-day conference, you can choose from over 130 sessions in multiple tracks and 25 workshops.

Carousel_PP_768x460_Wave2 (1).png

2022 Release Wave 2 Plan

Power Platform release plan for the 2022 release wave 2 describes all new features releasing from October 2022 through March 2023.

Users online (3,677)