Using rounded corners with DataTables in R programming

I am seeking assistance with implementing round borders on my DT table in R. My JavaScript skills are limited, so I would greatly appreciate any help or guidance on how to achieve this.

My current code is as follows:

DT::datatable(
  data = iris,
  options = list(
    initComplete = DT::JS(
      "function(settings, json) {",
      paste0(
        "$(this.api().table().header()).css({
          'background-color': 'black',
          'color': 'white',
          'border-top-left-radius': '4px',
          'border-top-right-radius': '4px'
          });"
      ),
      "}"
    )
  )
)

The style attribute border-top-left-radius does not seem to be effective for creating round corners. I believe a solution like the one provided in this answer using pure JS could resolve the issue, but I need assistance incorporating it into my R code.

Attached is a screenshot of my current table layout, where I aim to have rounded corners at the top left and right rather than sharp edges.

https://i.sstatic.net/sILYV.png

Answer №1

You must include the CSS property overflow: hidden.

DT::datatable(
  data = iris,
  options = list(
    initComplete = DT::JS(
      "function(settings, json) {",
      paste0(
        "$(this.api().table().header()).css({
          'background-color': 'black',
          'color': 'white',
          'border-top-left-radius': '4px',
          'border-top-right-radius': '4px', 
          'display': 'none'
          });"
      ),
      "}"
    )
  )
)

Answer №2

Check out this code snippet that I found on the datatables forum which helped me achieve the desired outcome:

DT::datatable(
  data = iris,
  options = list(
    initComplete = DT::JS(
      "function(settings, json) {",
      "$('th').css({'background-color': 'black'});",
      "$('th').css({'color': 'white'});",
      "$('th:first-child').css({'border-top-left-radius': '15px'});",
      "$('th:last-child').css({'border-top-right-radius': '15px'});",
      "}"
    )
  )
)

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

The problem of duplicate ids: Once an id is used, it cannot be

Currently, I'm focusing on a specific script : http://www.andwecode.com/playground-demo/pop-up-login-signup-box-jquery/# I've made some adjustments to the Gmail and Facebook boxes within this script. When clicking on them, I want them to displa ...

The absence of a declaration file for a module results in it implicitly having an 'any' type, particularly when trying to import a portion of a CommonJS module

Presently, the project utilizes a CommonJS module to store configuration values in a single file: module.exports = { classA: `classA`, classB: `classB` classC: `classC` } This makes it easy to reuse these values for creating JS selectors by followi ...

Specify the upper limit for a numeric input using Vuejs

My Vue.js script looks like the following: <template> <div> <div v-if='cart.length > 0'> <h1>Your Cart</h1> <template> <fieldset v-for='produc ...

Guide on how to reload the page with its initial URL after the URL has been modified using history.pushState()

After utilizing history.pushState(), I encountered an issue where the page would refresh with the current URL instead of the original one when the user refreshed the page. I attempted to detect a page refresh using methods such as cookies and hidden field ...

Tips on spotlighting Table of Contents with IntersectionObserver in NEXT JS

Currently working on my NextJS app and hoping to find a way to highlight the table of contents entry when its content is visible. Stumbled upon this helpful solution: https://css-tricks.com/table-of-contents-with-intersectionobserver/ but unsure how to a ...

Utilizing regex to eliminate irregular spaces and achieve an equal number of spaces in a character array

How can I implement this functionality in JavaScript? The concept involves checking the number of spaces that appear after a specific pattern in a character array. If the number of spaces is odd, one space should be removed to make it even. If the number o ...

Styling for the DataTable disappears upon loading jQuery

my PHP file named "zero3data.php" <?php printf('<table cellpadding="0" cellspacing="0" border="0" class="display" id="example" width="100%">'); printf('<thead>'); printf('<tr>'); ...

What techniques can I utilize to ensure Azure function generates JSON specifically for web browsers?

I have a functioning Azure function with the following code: module.exports = function(context, req) { // this is the complete source code, believe it or not context.done(null, {favoriteNumber: 3}); }; When I utilize a tool like Postman to access ...

Leverage Vue's ability to assign data from a parent component to

I am struggling to bind the data (inputData) from the parent component to my child component. I have checked my code multiple times but cannot find where the mistake is. MainApp.js let vm = new Vue({ el: "#app", components: { &ap ...

Notifying when a refreshed PHP interactive clock has detected new input

I have created a simple countdown timer in PHP that will continuously update the result to be displayed on the page using JavaScript. I am still deciding whether updating every second could potentially cause any issues. The way the countdown works is by r ...

Guide on deploying Google App Script add-ons on Google Workspace Marketplace

Recently delving into Google App Script, I've taken my first steps in coding within the platform. Utilizing the deploy option provided by Google App Script, I successfully launched my app. However, upon deployment, I encountered difficulty locating my ...

constructing a new array instance through pushing JSON documents

There are two objects which I have defined: var id = "one"; var arrobj = Array[2] 0: Object name : "a" desc : "desc1" 1: Object name : "b" desc : "desc2" My goal is to create the object in the following structure ...

Angular request accessing CoinMarketCap API

Currently, I am immersing myself in the world of the latest CoinMarketCap API and navigating through the waters of data. The Node.js example below demonstrates how to make a request. But how can I achieve the same in Angular? Any tips or suggestions would ...

Is there a way to dynamically change the source of an image based on different screen sizes using Tailwind CSS?

Currently, I am utilizing the next/Image component for setting an image and applying styling through tailwindcss. However, I have encountered a roadblock at this juncture. My Objective My goal is to dynamically change the src attribute of the image based ...

Angular UI-Router has a quirk where it may execute a controller twice upon loading if it is defined within the

Every time I run the code in my controller, it seems to be executed twice, resulting in duplicate outputs in the console.log window of Chrome Dev Tools. questions.html <div ng-controller="questionController as vm"> </div> questionController. ...

Nodejs and mysql integrated login system using express

I have created a node.js Express login system with MySQL. Registration and login services are working fine, but the logout functionality is not. Additionally, I want to restrict access to certain pages only to admin users. Here is the file structure: ...

A guide to displaying a PDF preview using React Dropzone

I am struggling to find a way to display previews of PDF files that I'm uploading using react-dropzone. Although PNG and JPG files are working correctly, I would like to be able to show the user either the actual PDF or an image representation of it. ...

I keep seeing repetitive label text in my jQuery code

When using jQuery to retrieve the text of a checked radio button label and selected select option, I am encountering duplicated text: <form> <fieldset> <ul> <li> <input type="radio" name="exportType" valu ...

Utilizing Jquery for Mouse Clicks

Is there a way to simulate a mouse click using jQuery? <div id="myId> Simulate Mouse Click programatically</div> I currently have a mouse listener set up. $("#myId").mousedown(function(){ alert("Mouse clicked programatically"); }) ...

Forecasting using a subset in R

Below is the code I am currently working with: install.packages("wooldridge") library(wooldridge) data(wage1) wage1reg<-lm(lwage ~ educ + exper + tenure, data = wage1) My objective is to predict fitted values for these three variables based on their ...