JQuery Dategrid Adaptive width

Source: Internet
Author: User

I think the friend who is using the jquery easy UI must very much hope that the DataGrid can adapt to the page size changes, I have not yet found that it comes with this function, so I wrote a simple implementation method, share with netizens, also hope to help needy friends.

Here is an implementation of my jquery based:

JS Code
  1. /**
  2. * jquery extension method, the user to jquery Easyui the DataGrid control to operate.
  3. */
  4. $.fn.extend ({
  5. /** 
  6. * Modify the default size of the DataGrid object to fit the page width.
  7. *
  8. * @param heightmargin
  9. * height is the distance from the inside margin of the page.
  10. * @param widthmargin
  11. * Width is the distance from the inside margin of the page.
  12. * @param minheight
  13. * Minimum height.
  14. * @param minWidth
  15. * Minimum width.
  16. *
  17. */
  18. Resizedatagrid: function (Heightmargin, Widthmargin, MinHeight, minWidth) {
  19. var height = $ (document.body). Height ()-heightmargin;
  20. var width = $ (document.body). Width ()-widthmargin;
  21. Height = height < minheight? Minheight:height;
  22. width = width < minWidth? Minwidth:width;
  23. $ (this). DataGrid (' resize ', {
  24. Height:height,
  25. Width:width
  26. });
  27. }
  28. });



How to use:

JS Code
  1. $ (function () {
  2. var datagridid = ' Userdatagrid ';
  3. //other code
  4. //Auto change size on first load
  5. $ (' # ' + datagridid). Resizedatagrid (20, 20, 300, 600);
  6. //Adjust the size of the DataGrid when the window size is changed
  7. $ (window). Resize (function () {
  8. $ (' # ' + datagridid). Resizedatagrid (20, 20, 300, 600);
  9. });
  10. });



In addition, because IE6 JS is inefficient, so in order to make the DataGrid adaptive page size changes, please set the DataGrid Fitcolumns property to False, otherwise changing the page size will cause IE to appear a certain time to pause. Set the method to:

$ (' # ' + Datagridid). DataGrid ({
Title: ' User type ',
URL: ' Usertype.json ',
Fitcolumns:false,
.......

JQuery Dategrid Adaptive width

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.