I struggle to randomize the gallery after filtering.

Thanks for helping me.

I must have misunderstood something here. I am not sure how to “map your data field keys to gallery items keys” using the code.

This is my first time even doing something with the code. So far I can kinda understand some simple stuff you see in my code but with help of copy/paste.

import wixData from ‘wix-data’ ; //This line must be at the top of the page code

async function bindData () {
const itemsRetrival = await $w ( ‘#dataset1’ ). getItems ( 0 , 1000 );
const items = itemsRetrival.items ;
for ( let i = items.length - 1 ; i > 0 ; i --) {
const j = Math . floor ( Math.random () * ( i + 1 ));
[ items[i ], items[j ]] = [ items[j ], items[i ]];
}

$w ( ‘#gallery1’ ). items = items . map ( e => ({ src : ‘mainProjectImage’ , link : ‘link’ , title : ‘title’ }));
})

$w . onReady (() => {
$w ( ‘#dataset1’ ). onReady ( bindData );
})

$w . onReady (() => {

        $w ( "#sveicon1" ). hide () 
        $w ( "#line1ex" ). hide () 
        $w ( "#line4" ). hide () 
        $w ( "#line5" ). hide () 
        $w ( "#logotipibutton1" ). hide () 
        $w ( "#logotipibutton2" ). hide () 
        $w ( "#webbanneri1" ). hide () 
        $w ( "#webbanneri2" ). hide () 

        $w ( "#sveicon1" ). onClick (() => {  // SVE FILTER KLIK 

                $w ( "#grafickidizajnbutton1" ). show () 
                $w ( "#grafickidizajnbutton2" ). hide () 
                $w ( "#oslikavanjevozilabutton1" ). show () 
                $w ( "#oslikavanjevozilabutton2" ). hide () 
                $w ( "#fotomanipulacijebutton1" ). show () 
                $w ( "#fotomanipulacijebutton2" ). hide () 
                $w ( "#logotipibutton1" ). hide () 
                $w ( "#logotipibutton2" ). hide () 
                $w ( "#webbanneri1" ). hide () 
                $w ( "#webbanneri2" ). hide () 
                $w ( "#sveicon1" ). hide () 
                $w ( "#sveicon2" ). show () 
                $w ( "#line1ex" ). hide () 
                $w ( "#line4" ). hide () 
                $w ( "#line5" ). hide () 

                function  filterData () { 

                    $w ( "#dataset1" ). setFilter ( wixData.filter (). eq ( 'tag2' ,  filter )). then ( bindData ); 
                }) 

            $w ( "#grafickidizajnbutton1" ). onClick (() => {  // GRAFICKI DIZAJN FILTER KLIK 

                $w ( "#grafickidizajnbutton1" ). hide () 
                $w ( "#grafickidizajnbutton2" ). show () 
                $w ( "#oslikavanjevozilabutton1" ). show () 
                $w ( "#oslikavanjevozilabutton2" ). hide () 
                $w ( "#fotomanipulacijebutton1" ). show () 
                $w ( "#fotomanipulacijebutton2" ). hide () 
                $w ( "#logotipibutton1" ). show () 
                $w ( "#logotipibutton2" ). hide () 
                $w ( "#webbanneri1" ). show () 
                $w ( "#webbanneri2" ). hide () 
                $w ( "#sveicon1" ). show () 
                $w ( "#sveicon2" ). hide () 
                $w ( "#line1ex" ). show () 
                $w ( "#line4" ). show () 
                $w ( "#line5" ). show () 

                let  filter  =  $w ( "#grafickidizajnbutton1" ). label 

                $w ( "#dataset1" ). setFilter ( wixData.filter () 
                    . eq ( 'tag' ,  filter ) 

                ) 
            }) 

            $w ( "#oslikavanjevozilabutton1" ). onClick (() => {  // OSLIKAVANJE VOZILA FILTER KLIK 

                $w ( "#grafickidizajnbutton1" ). show () 
                $w ( "#grafickidizajnbutton2" ). hide () 
                $w ( "#oslikavanjevozilabutton1" ). hide () 
                $w ( "#oslikavanjevozilabutton2" ). show () 
                $w ( "#fotomanipulacijebutton1" ). show () 
                $w ( "#fotomanipulacijebutton2" ). hide () 
                $w ( "#logotipibutton1" ). hide () 
                $w ( "#logotipibutton2" ). hide () 
                $w ( "#webbanneri1" ). hide () 
                $w ( "#webbanneri2" ). hide () 
                $w ( "#sveicon1" ). show () 
                $w ( "#sveicon2" ). hide () 
                $w ( "#line1ex" ). hide () 
                $w ( "#line4" ). hide () 
                $w ( "#line5" ). hide () 

                let  filter  =  $w ( "#oslikavanjevozilabutton1" ). label 

                $w ( "#dataset1" ). setFilter ( wixData.filter () 
                    . eq ( 'tag' ,  filter ) 

                ) 
            }) 

            $w ( "#fotomanipulacijebutton1" ). onClick (() => {  // FOTOMANIPULACIJE FILTER KLIK 

                $w ( "#grafickidizajnbutton1" ). show () 
                $w ( "#grafickidizajnbutton2" ). hide () 
                $w ( "#oslikavanjevozilabutton1" ). show () 
                $w ( "#oslikavanjevozilabutton2" ). hide () 
                $w ( "#fotomanipulacijebutton1" ). hide () 
                $w ( "#fotomanipulacijebutton2" ). show () 
                $w ( "#logotipibutton1" ). hide () 
                $w ( "#logotipibutton2" ). hide () 
                $w ( "#webbanneri1" ). hide () 
                $w ( "#webbanneri2" ). hide () 
                $w ( "#sveicon1" ). show () 
                $w ( "#sveicon2" ). hide () 
                $w ( "#line1ex" ). hide () 
                $w ( "#line4" ). hide () 
                $w ( "#line5" ). hide () 

                let  filter  =  $w ( "#fotomanipulacijebutton1" ). label 

                $w ( "#dataset1" ). setFilter ( wixData.filter () 
                    . eq ( 'tag' ,  filter ) 

                ) 
            }) 

            $w ( "#logotipibutton1" ). onClick (() => {  // LOGOTIPI FILTER KLIK 

                $w ( "#grafickidizajnbutton1" ). show () 
                $w ( "#grafickidizajnbutton2" ). hide () 
                $w ( "#oslikavanjevozilabutton1" ). show () 
                $w ( "#oslikavanjevozilabutton2" ). hide () 
                $w ( "#fotomanipulacijebutton1" ). show () 
                $w ( "#fotomanipulacijebutton2" ). hide () 
                $w ( "#logotipibutton1" ). hide () 
                $w ( "#logotipibutton2" ). show () 
                $w ( "#webbanneri1" ). show () 
                $w ( "#webbanneri2" ). hide () 
                $w ( "#sveicon1" ). show () 
                $w ( "#sveicon2" ). hide () 

                let  filter  =  $w ( "#logotipibutton1" ). label 

                $w ( "#dataset1" ). setFilter ( wixData.filter () 
                    . eq ( 'tag2' ,  filter ) 

                ) 
            }) 

            $w ( "#webbanneri1" ). onClick (() => {  // WEB BANNERI FILTER KLIK 

                $w ( "#grafickidizajnbutton1" ). show () 
                $w ( "#grafickidizajnbutton2" ). hide () 
                $w ( "#oslikavanjevozilabutton1" ). show () 
                $w ( "#oslikavanjevozilabutton2" ). hide () 
                $w ( "#fotomanipulacijebutton1" ). show () 
                $w ( "#fotomanipulacijebutton2" ). hide () 
                $w ( "#logotipibutton1" ). show () 
                $w ( "#logotipibutton2" ). hide () 
                $w ( "#webbanneri1" ). hide () 
                $w ( "#webbanneri2" ). show () 
                $w ( "#sveicon1" ). show () 
                $w ( "#sveicon2" ). hide () 

                let  filter  =  $w ( "#webbanneri1" ). label 

                $w ( "#dataset1" ). setFilter ( wixData.filter () 
                    . eq ( 'tag2' ,  filter ) 

                ) 
            }) 

        });