المكتبة التقنية ←

تلوين صفوف تقارير Oracle APEX باستخدام SQL وCSS

English version

A status column can help readers scan an Oracle APEX Interactive Report quickly. My original LinkedIn example used a small HTML marker inside each row, then CSS to style the row containing that marker.

Return a controlled status marker

The following illustrative query assumes a table named demo_records with record_id and status_code. Replace those names with your application's query. The status mapping emits a fixed set of HTML strings.

select record_id,
       case status_code
         when 'VALID' then
           '<span class="row-paint" data-state="valid">Valid</span>'
         when 'EXPIRED' then
           '<span class="row-paint" data-state="expired">Expired</span>'
         else
           '<span class="row-paint" data-state="review">Review</span>'
       end as status_badge
from demo_records

Set the computed STATUS_BADGE column to Plain Text and set Escape Special Characters to No so its generated markup can render. Keep ordinary data columns escaped. If you extend the expression to include user-entered text, escape that text for its output context before combining it with HTML. Oracle documents HTML and attribute escaping.

The visible words Valid, Expired, and Review give each row a readable status alongside its color.

Scope the CSS to one report

Give the report region the Static ID record_status_report. Add these rules to your application stylesheet or the page's Inline CSS.

#record_status_report tbody tr:has(.row-paint[data-state="valid"]) > td {
  background-color: #e4f5ea;
  color: #123b24;
}

#record_status_report tbody tr:has(.row-paint[data-state="expired"]) > td {
  background-color: #fbe9e7;
  color: #582018;
}

The :has() selector matches a row containing the corresponding marker. Applying the background to its cells helps the color appear over cell backgrounds supplied by the report template. MDN explains the selector and browser support.

The Review state keeps the report's normal styling. Adjust the palette for your theme and check contrast in every supported appearance.

Verify the complete report experience

Test the two colored states and the fallback state. Change filters, sort columns, move between report pages, and refresh the report. The selector will match newly rendered rows when the marker remains in their markup.

Keep the status column in the report layouts that need this treatment. If users hide or exclude that column, verify whether the marker remains in the rendered DOM. Check keyboard focus, hover styling, small screens, and downloads as well. An export should communicate the status through readable values.

This pattern connects a controlled status value to presentation. Keep the underlying business decision in the query or application logic, and use the visible label to explain the color.

النسخة العربية

عمود الحالة يساعد المستخدم يراجع صفوف Interactive Report في Oracle APEX بسرعة. المثال الأصلي على LinkedIn استخدم علامة HTML صغيرة داخل كل صف، وبعدها CSS لتنسيق الصف الذي يحتوي على العلامة.

أرجع علامة حالة بقيم محددة

الاستعلام التوضيحي التالي يفترض وجود جدول demo_records وعمودي record_id وstatus_code. استبدل الأسماء باستعلام تطبيقك. الربط بين الحالة والعرض يُنتج مجموعة ثابتة من نصوص HTML.

select record_id,
       case status_code
         when 'VALID' then
           '<span class="row-paint" data-state="valid">Valid</span>'
         when 'EXPIRED' then
           '<span class="row-paint" data-state="expired">Expired</span>'
         else
           '<span class="row-paint" data-state="review">Review</span>'
       end as status_badge
from demo_records

اضبط العمود المحسوب STATUS_BADGE على Plain Text واجعل Escape Special Characters بقيمة No لعرض HTML الناتج. احتفظ بالـEscaping لأعمدة البيانات العادية. لو وسّعت التعبير وأضفت نصًا يدخله المستخدم، طبّق عليه الـEscaping المناسب لسياق العرض قبل دمجه مع HTML. توضح Oracle فلاتر حماية النصوص وخصائص HTML.

الكلمات الظاهرة Valid وExpired وReview توفر وصفًا مقروءًا للحالة بجانب اللون.

حدّد نطاق CSS لتقرير واحد

أعطِ منطقة التقرير Static ID بقيمة record_status_report. أضف القواعد التالية إلى ملف CSS الخاص بالتطبيق أو Inline CSS في الصفحة.

#record_status_report tbody tr:has(.row-paint[data-state="valid"]) > td {
  background-color: #e4f5ea;
  color: #123b24;
}

#record_status_report tbody tr:has(.row-paint[data-state="expired"]) > td {
  background-color: #fbe9e7;
  color: #582018;
}

المحدد :has() يختار الصف الذي يحتوي على العلامة المطابقة. تطبيق الخلفية على خلايا الصف يساعد اللون يظهر فوق الخلفيات التي يضعها قالب التقرير على الخلايا. يشرح MDN المحدد ودعم المتصفحات له.

حالة Review تحتفظ بتنسيق التقرير المعتاد. عدّل الألوان لتناسب الثيم، وراجع تباين النص في كل مظهر يدعمه التطبيق.

اختبر تجربة التقرير كاملة

اختبر الحالتين الملونتين والحالة الافتراضية. غيّر الفلاتر والترتيب، وتنقّل بين صفحات التقرير، ثم حدّثه. المحدد يطابق الصفوف التي تُرسم من جديد عندما تظل العلامة موجودة في HTML الخاص بها.

احتفظ بعمود الحالة في تخطيطات التقرير التي تحتاج التنسيق. لو المستخدم أخفى العمود أو استبعده، افحص هل العلامة ما زالت موجودة في الـDOM الناتج. راجع تركيز الكيبورد وتنسيق مرور المؤشر والشاشات الصغيرة وتنزيل الملفات أيضًا. ملف التصدير يحتاج قيمًا مقروءة توضّح الحالة.

الأسلوب يربط قيمة حالة محددة بطريقة عرضها. احتفظ بقرار العمل في الاستعلام أو منطق التطبيق، واستخدم النص الظاهر لتفسير اللون.