javve / list.pagination.js

A pagination plugin for List.js
24 stars 23 forks source link

Does not work on Ajax data #23

Closed daksamedia closed 7 years ago

daksamedia commented 7 years ago

Hello @javve , I'm very happy finally found a simply plugin to listing, filtering, and paginating.

Unfortunately, I'm working on Ajax data that has really complex data. Here is the code :

$.ajax({
                type : "POST",
                url : baseUrl + "/kp/itemCache",
                data :  "itemIds="+itemdIds ,   
                success : function(data) {

                /*  * list Property
                    *
                    * data.id               item Id
                    * data.title            item name
                    * data.price            item price
                    * data.saleprice        item saleprice
                    * data.linkUrl          item PDP link
                    * data.image            item image uploaded by seller
                    * data.ribbon           discount value
                    * data.quantity         quantity produk
                    * data.qtyStatus        status quantity produk (available = 1 / not-available = 0)
                    * data.discountEndTime  discount end-time for item LTD 
                    * data.countdown        countdown for limit discount time (LTD)
                    * data.limitNum         limit quantity for LTD 
                    */ 

                    var arrOffShelfItem = itemdIds.slice();

                    if(data){   
                        var arrData = eval(data);
                        $.each(itemdIds, function(n, value) {

                            var checkResult = false;

                            $.each(arrData, function(index, content){

                                if(value == content.id && (value != undefined && content.id != undefined)){
                                    $(".salePrice-"+value).html("Rp "+content.salePrice+" ");
                                    $(".price-"+value+" del").html("Rp "+content.price+" ");

                                    var price = Number(content.price.replace(/[^0-9\,]+/g,""));
                                    var salePrice = Number(content.salePrice.replace(/[^0-9\,]+/g,""));

                                    if(content.ribbon == undefined && (price != undefined && price > 0)){
                                        content.ribbon = ((price - salePrice) / price) * 100;
                                        content.ribbon = Math.round(content.ribbon);
                                    }
                                    $(".dis-"+value).html(""+content.ribbon+"% ");

                                    if(content.ribbon == undefined && (price == undefined || price < 1)){
                                        $(".dis-"+value).hide();
                                    }

                                    if(content.countdown != undefined && content.countdown > 0) {                                                                       
                                        arrCountdown[arrCountdownPrefix+""+value] = content.countdown;
                                        setInterval("countdownFun("+value+")", 1000);
                                    }else{
                                        if($(".countdown-"+value))
                                            $(".countdown-"+value).hide();
                                    }

                                    if(content.price == undefined || content.price < 1){
                                        $(".price-"+value).before("<br />");
                                        $(".price-"+value).hide();
                                    }

                                    var prodImg = $("div[itemId="+value+"]").find("img");
                                    if(prodImg) {
                                        prodImg.attr("data-original", ""+content.image+"_180x180.jpg");

                                    }

                                    //var prodImg = $("div[itemId="+value+"]").find("#gambar");
                                    //if(prodImg) {
                                        //prodImg.css("background-image", "url("+content.image+"_348x348.jpg)");                                    
                                    //}

                                    var prodTitle = $("div[itemId="+value+"]").find("h2");
                                    if(prodTitle) {

                                        prodTitle.html(content.title);
                                    }

                                    userList = new List('users', opsi);

                                    //http://item.blanja.com/item/jual-beli-eolins-5-sarung-bantal-sofa-daun-jsps044-rainbow-14586720?ref=[Onsite-20162104-17-3-CP000253-14586720]
                                    //ref=[Onsite-dateCamp-week-category-CampId-ProductId]
                                    //ref=[Onsite-20162104-17-3-CP000253-14586720]

                                    // define your tracking here

                                    var tracking = "ref=[Onsite-20151905-21-1-CP000239-"+value+"]";

                                    var linkPdp = content.linkUrl;
                                    var linkPdpWithTracking = linkPdp + "?" + tracking;                                 

                                    var pdpHref = $("div[itemId="+value+"]").find("a");
                                    if(pdpHref) {
                                        pdpHref.attr("href", linkPdpWithTracking);
                                    }

                                    var i = arrOffShelfItem.indexOf(value);
                                    arrOffShelfItem.splice(i, 1);
                                }                   
                            });
                        });
                    }`

Is there anyone here who has an experience using list.pagination.js plugin to load and paginate the ajax data?

If so, please kindly send your help here.

Thank you very much.

Best Regards.