顯示具有 jquery 標籤的文章。 顯示所有文章
顯示具有 jquery 標籤的文章。 顯示所有文章

2015年1月12日 星期一

[jQuery] Datatable: Some Hints

Be careful when using datatables, the following should take into account

  1. If you try to do some column visible/invisible work, you need to clear cookies to take effect or you may not see any differences
     
    $('#example').dataTable( {
      "columnDefs": [
        { "visible": false, "targets": 0 }
      ]
    } );

    For the above, we specify the column 0 to be invisible, but when I refresh my page, I cannot see anything, we need to clear the cookies to achieve the changes, the only reason for this I guess would be the bState parameter which use the cookie to save the sorting history and other datatable profiles.

    ***And usually you may need to restart the chrome browser with the private mode to reflect the changes***

I will update this doc if any new hints of datatables found.

2014年12月23日 星期二

[jQuery] Find selected option with "this"

Usually, when we want to get the selected option's text using jQuery, we will use the following method.

var selVal = $("selObj#selID option:selected").val()

What if the target object is "this"? We will instead use the following

var selVal = $("option:selected", this).prop("value");

2014年12月18日 星期四

[jQuery] About .data() and $.data()

$.data >> Old school method, data may not be retrieved successfully after assigning data to the DOM.

Use el.data() instead to ensure greatest compatibility