简体   繁体   English

如何覆盖.js文件内容

[英]How to override the .js file contents

im using the datatable.js library in my application, but i need to modify certain styles in the datatable.js, its working fine if i directly modify the styles in .js file. 我在我的应用程序中使用datatable.js库,但是我需要在datatable.js中修改某些样式,如果我直接修改.js文件中的样式,它的工作效果很好。 Changes looks like below. 更改如下所示。

/* Sorting */
        "sSortAsc": "ui-state-default_custom",
        "sSortDesc": "ui-state-default_custom",
        "sSortable": "ui-state-default_custom",
        "sSortableAsc": "ui-state-default_custom",

/* Scrolling */
        "sScrollHead": "dataTables_scrollHead ui-state-default_custom",
        "sScrollFoot": "dataTables_scrollFoot ui-state-default_custom",

But this is not recommended as it makes changes directly to lib, is there a way to avoid and override these changes in some other file and use it? 但是不建议这样做,因为它直接对lib进行更改,是否有办法避免和覆盖其他文件中的更改并使用它?

Do it exactly as it is described in the sourcecode : 完全按照源代码中的描述进行操作:

Extension object for DataTables that is used to provide all extension options. DataTables的扩展对象,用于提供所有扩展选项。

Note that the DataTable.ext object is available through jQuery.fn.dataTable.ext where it may be accessed and manipulated. 请注意,可以通过jQuery.fn.dataTable.ext访问DataTable.ext对象,在该对象中可以对其进行访问和操作。

So, if you have a style like this 所以,如果你有这样的风格

.my-sorting {
    background-color: red;
}

and you want to use that class in sortable <thead> 's instead of the default "sSortable": "sorting" simply add this before your dataTable() initialization : 并且您想在sortable <thead>使用该类,而不是默认的"sSortable": "sorting"只需在dataTable()初始化之前添加此类:

jQuery.fn.dataTable.ext.oStdClasses.sSortable='my-sorting';

You can change all of your above mentioned default properties by that, and much more, without changing the original source. 您可以更改所有上述默认属性,并且进行更多更改,而无需更改原始源。

Here is a fiddle with the above example you can test on : http://jsfiddle.net/rbUAq/ 这是上面例子的小提琴,您可以在以下位置进行测试: http : //jsfiddle.net/rbUAq/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM